『威风八面』 『威风八面』
关注数: 20 粉丝数: 15 发帖数: 290 关注贴吧数: 10
为什么使用lineEdit->text().toInt()会出现程序中断啊 #include<qapplication.h> #include<QDialog> #include<QLabel> #include<QLineEdit> #include<QComboBox> #include<QProgressBar> #include<QProgressDialog> #include<QPushButton> #include<QGridLayout> class Progress:public QDialog { Q_OBJECT private: QPushButton *start; QProgressBar *progressBar; QLineEdit *numsLine; QComboBox *typeCombo; private slots: void showProgress() { bool ok; QString s=numsLine->text(); int num=s.toInt(&ok); if(!ok) return; if(typeCombo->currentIndex ()==0) { int i=1; for(;i<num+1;i++) progressBar->setValue(i); } else { QProgressDialog *dialog=new QProgressDialog(this); dialog->setMinimumDuration(5); dialog->setWindowTitle("Pleaase wait"); dialog->setLabelText("Copying..."); dialog->setCancelButtonText("Cancel"); dialog->setRange(0,num); for(int i=1;i<num+1;i++) { dialog->setValue(i); if(dialog->wasCanceled () ) { delete dialog; return ; } } } } public: Progress(QWidget* parent =0):QDialog(parent) { QLabel *numsLabel=new QLabel("files nums:"); QLabel *typeLabel=new QLabel("types to display:"); QLineEdit *numsLine=new QLineEdit("500"); QComboBox *typeCombo=new QComboBox; typeCombo->addItem("progressBar"); typeCombo->addItem("progressDialog"); progressBar=new QProgressBar; start=new QPushButton("&Start"); QGridLayout *layout=new QGridLayout(this); layout->addWidget(numsLabel,0,0); layout->addWidget(typeLabel,1,0); layout->addWidget(numsLine,0,1); layout->addWidget(typeCombo,1,1); layout->addWidget(progressBar,2,0,1,2); layout->addWidget(start,3,1); connect(start,SIGNAL(clicked() ),this, SLOT(showProgress()) ); } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); Progress *p=new Progress; p->show(); return a.exec(); }
1 下一页