標籤:extc void private name enable lld .com efi his
1. 使用Qt設計師建立GoToCell對話方塊。
2. gotocelldialog.cpp
1 #include <QRegExp> 2 3 #include "gotocelldialog.h" 4 5 GoToCellDialog::GoToCellDialog(QWidget *parent) 6 : QDialog(parent) 7 { 8 setupUi(this); /*初始化表單*/ 9 /*setupUi()函數會自動將符合on_objectName_signalName()命名慣例的任意槽10 與相應的objectName的signalName()訊號串連到一起。*/11 12 /*{0,2}中2前面不能有空格,有空格的話,lineEdit框中無法輸入*/13 QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");14 /*QRegExpValidator檢驗器類*/15 /*把this傳遞給QRegExpValidator的建構函式,使它成為GoToCellDialog對象的一個子物件*/16 lineEdit->setValidator(new QRegExpValidator(regExp, this));17 18 connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));19 connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));20 }21 22 /*啟用或禁用OK按鈕*/23 void GoToCellDialog::on_lineEdit_textChanged()24 {25 /*QLineEdit::hasAcceptableInput()會使用在建構函式中設定的檢驗器來判斷行編輯器中內容的有效性*/26 okButton->setEnabled(lineEdit->hasAcceptableInput());27 }
3. gotocelldialog.h
1 /**/ 2 #ifndef GOTOCELLDIALOG_H 3 #define GOTOCELLDIALOG_H 4 5 #include <QDialog> 6 7 #include "ui_gotocelldialog.h" 8 9 class GoToCellDialog : public QDialog, public Ui::GoToCellDialog10 {11 Q_OBJECT12 13 public:14 GoToCellDialog(QWidget *parent = 0);15 16 private slots:17 void on_lineEdit_textChanged();18 };19 20 #endif
4. main.cpp
1 #include <QApplication> 2 3 #include "gotocelldialog.h" 4 5 int main(int argc, char *argv[]) 6 { 7 QApplication app(argc, argv); 8 9 GoToCellDialog *dialog = new GoToCellDialog;10 dialog->show();11 12 return app.exec();13 }14 15 #if 016 17 #include <QApplication>18 #include <QDialog>19 20 #include "ui_gotocelldialog.h"21 22 23 int main(int argc, char *argv[])24 {25 QApplication app(argc, argv);26 27 Ui::GoToCellDialog ui;28 QDialog *dialog = new QDialog;29 ui.setupUi(dialog);30 dialog->show();31 32 return app.exec();33 }34 35 #endif
C++ GUI Qt4編程(05)-2.2GoToCell