先构建一份ui:
// content:
6,
// revision
0,
// classname
0,
0, // classinfo
1,
14, // methods
0,
0, // properties
0,
0, // enums/sets
0,
0, // constructors
0,
// flags
0,
// signalCount
// slots: signature, parameters, type, tag, flags
16,
15,
15,
15, 0x08,
0
// eod
"GoToCellDialog\0\0on_lineEdit_textChanged()\0"
if (_c == QMetaObject::InvokeMetaMethod) {
Q_ASSERT(staticMetaObject.cast(_o));
GoToCellDialog *_t = static_cast(_o);
switch (_id) {
case 0: _t->on_lineEdit_textChanged(); break;
default: ;
}
}
Q_UNUSED(_a);
0,
qt_static_metacall
{ &QDialog::staticMetaObject, qt_meta_stringdata_GoToCellDialog,
qt_meta_data_GoToCellDialog, &staticMetaObjectExtraDat
a }
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_GoToCellDialog))
return static_cast(const_cast< GoToCellDialog*>(this));
if (!strcmp(_clname, "Ui::GoToCellDialog"))
return static_cast< Ui::GoToCellDialog*>(const_cast< GoToCellDialog*>(this));
return QDialog::qt_metacast(_clname);
_id = QDialog::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 1)
qt_static_metacall(this, _c, _id, _a);
_id -= 1;
}
return _id;
QVBoxLayout *verticalLayout;
QHBoxLayout *horizontalLayout;
QLabel *label;
QLineEdit *lineEdit;
QHBoxLayout *horizontalLayout_2;
QSpacerItem *horizontalSpacer;
QPushButton *okButton;
QPushButton *cancelButton;
void setupUi(QDialog *GoToCellDialog)
{
if (GoToCellDialog->objectName().isEmpty())
GoToCellDialog->setObjectName(QString::fromUtf8("GoToCellDialog"));
GoToCellDialog->resize(249, 71);
verticalLayout = new QVBoxLayout(GoToCellDialog);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
horizontalLayout = new QHBoxLayout();
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
label = new QLabel(GoToCellDialog);
label->setObjectName(QString::fromUtf8("label"));
horizontalLayout->addWidget(label);
lineEdit = new QLineEdit(GoToCellDialog);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
horizontalLayout->addWidget(lineEdit);
verticalLayout->addLayout(horizontalLayout);
horizontalLayout_2 = new QHBoxLayout();
horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer);
okButton = new QPushButton(GoToCellDialog);
okButton->setObjectName(QString::fromUtf8("okButton"));
okButton->setEnabled(false);
okButton->setDefault(true);
horizontalLayout_2->addWidget(okButton);
cancelButton = new QPushButton(GoToCellDialog);
cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
horizontalLayout_2->addWidget(cancelButton);
verticalLayout->addLayout(horizontalLayout_2);
retranslateUi(GoToCellDialog);
QMetaObject::connectSlotsByName(GoToCellDialog);
} // setupUi
void retranslateUi(QDialog *GoToCellDialog)
{
GoToCellDialog->setWindowTitle(QApplication::translate("GoToCellDialog", "Dialog", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("GoToCellDialog", "
okButton->setText(QApplication::translate("GoToCellDialog", "OK", 0, QApplication::UnicodeUTF8));
cancelButton->setText(QApplication::translate("GoToCellDialog", "Cancel", 0, QApplication::UnicodeUTF8));
} // retranslateUi
class GoToCellDialog: public Ui_GoToCellDialog {};

自动生成文件1:moc_gotocelldialog.cpp
#include "../gotocelldialog.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'gotocelldialog.h' doesn't include ."
#elif Q_MOC_OUTPUT_REVISION != 63
#error "This file was generated using the moc from 4.8.2. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
static const uint qt_meta_data_GoToCellDialog[] = {
};
static const char qt_meta_stringdata_GoToCellDialog[] = {
};
void GoToCellDialog::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
}
const QMetaObjectExtraData GoToCellDialog::staticMetaObjectExtraDat
a = {
};
const QMetaObject GoToCellDialog::staticMetaObject = {
};
#ifdef Q_NO_DATA_RELOCATION
const QMetaObject &GoToCellDialog::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION
const QMetaObject *GoToCellDialog::metaObject() const
{
}
void *GoToCellDialog::qt_metacast(const char *_clname)
{
}
int GoToCellDialog::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
}
QT_END_MOC_NAMESPACE
文件2:
#ifndef UI_GOTOCELLDIALOG_H
#define UI_GOTOCELLDIALOG_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
QT_BEGIN_NAMESPACE
class Ui_GoToCellDialog
{
public:
Cell Location:
", 0, QApplication::UnicodeUTF8));
};
namespace Ui {
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_GOTOCELLDIALOG_H
1、手动完成UI的建立,然后在cmd 中用qmake -project 命令,生成gotocell.rpo(父目录即为工程名),再用make gotocell.pro中生成工程。需要在VS中编辑文件时:再使用qmake -tp vc gotocell.pro即可。上面的两份代码均为自动生成的
2、gotocelldialog.h
#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H
#include
#include "ui_gotocelldialog.h"
class GoToCellDialog:public QDialog,public Ui::GoToCellDialog
{
Q_OBJECT
public:
GoToCellDialog(QWidget *parent = 0);
private slots:
void on_lineEdit_textChanged();
};
#endif
3、gotocelldialog.cpp
#include
#include "gotocelldialog.h"
GoToCellDialog::GoToCellDialog(QWidget *parent)
:QDialog(parent)
{
setupUi(this);
QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
lineEdit->setValidator(new QRegExpValidator(regExp,this));
connect(okButton,SIGNAL(clicked()),this,SLOT(accept()));
connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
}
void GoToCellDialog::on_lineEdit_textChanged()
{
okButton->setEnabled(lineEdit->hasAcceptableInput());
}
3、main函数:
#include
#include
#include "gotocelldialog.h"
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
GoToCellDialog *dialog = new GoToCellDialog;
dialog->show();
return app.exec();
}
如果是用vs编辑工程的话,每次加入消息传递就是信号槽等处理,都得重新用cmd重新生成工程