解决Qt编写对话框出现的问题
来源:互联网 发布:驾驶远程教育及时软件 编辑:程序博客网 时间:2024/06/05 12:46
1. VS2008中,Qt Designer设计完对话框 xxx.ui ,用 uic.exe 生成头文件,用法: uic xxx.ui>ui_xxx.h
2. 将生成的 ui_xxx.h 添加进工程,在工程中添加类 Cxxx ,
xxx.h 中从 QDialog 和 ui_xxx.h 中继承过来:
class CGoToCellDialog : public QDialog, public Ui::GoToCellDialog{Q_OBJECTpublic:CGoToCellDialog(QWidget* parent = 0);~CGoToCellDialog(void);private slots:void on_lineEdit_textChanged();};
xxx.cpp 中在构造函数中这样写:
CGoToCellDialog::CGoToCellDialog(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()));}CGoToCellDialog::~CGoToCellDialog(void){}void CGoToCellDialog::on_lineEdit_textChanged(){okButton->setEnabled(lineEdit->hasAcceptableInput());}
3. 其中, setupUi 中会将 QtDesigner 中画的界面显示出来, setupUi 还会自动创建信号槽,规则为要符合 on_objectName_signalName() 的命名管理的任意槽于相应的
objectName 的 signalName的信号连接到一起,在这里有一个叫 lineEdit 的文本框,所有会自动完成下面的代码
connect( lineEdit, SIGNAL(textChanged()), this, SLOT(on_lineEdit_textChanged())) 。
4. 至此,编译程序,出现如下错误:
错误 1 error LNK2001: 无法解析的外部符号 "public: virtual struct QMetaObject const * __thiscall Widget::metaObject(void)const " (?metaObject@Widget@@UBEPBUQMetaObject@@XZ)
错误 2 error LNK2001: 无法解析的外部符号 "public: virtual void * __thiscall Widget::qt_metacast(char const *)" (?qt_metacast@Widget@@UAEPAXPBD@Z)
错误 3 error LNK2001: 无法解析的外部符号 "public: virtual int __thiscall Widget::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Widget@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
错误 4 fatal error LNK1120: 3 个无法解析的外部命令
这是因为在源文件中没有添加上 moc_xxx.cpp 文件,解决办法:
命令行:moc.exe xxx.h -o moc_xxx.cpp ,输出 moc_xxx.cpp ;将之添加至源文件中,再次编译,生成成功!
- 解决Qt编写对话框出现的问题
- 解决Qt:编写代码无提示的问题
- 解决WINRAR__出现付费对话框问题
- 解决qt mysql出现的:无法加载驱动问题
- 解决qt mysql出现的:无法加载驱动问题
- 如何解决编译Qt及Qvfb时出现的问题
- QT 播放flash出现空白间距问题的解决
- QT对话框出现消失的效果
- Qt 之 运行Qt Creator出现cannot find -lGL的问题的两种解决
- Qt 之 运行Qt Creator出现cannot find -lGL的问题的两种解决
- 关于启动PPT时,出现错误对话框的问题的解决.
- MFC编写对话框时遇到的问题
- 解决VC++6.0启动_【打开文件】_对话框时出现的“0x5003eaed”问题!!!
- 解决RedrawWindow()刷新界面出现闪烁的问题, VC对话框界面使用InvalidateRect刷新局部
- 解决Tslib移植之后自己编写的QT程序不能使用触屏的问题
- Qt模态对话框与非模态对话框的问题
- 解决ligerUi对话框出现双滚动条问题
- 添加自己编写的模块到ns-3中出现undefined reference to问题的解决
- 如何通过几何画板中文版快速等分线段
- 每个程序员都要遵守的一些优秀编程风格
- python 函数参数(必选参数、默认参数、可选参数、关键字参数)
- 统计矩阵和 二维树状数组 SPOJ 1029 Matrix Summation
- 集成支付宝 报错:rsa_private read error : private key is NULL
- 解决Qt编写对话框出现的问题
- 变位词 — 两种算法实现
- JSP Custom tags with example – JSP Tutorial
- leetcode 191 Number of 1 Bits(难易度:Easy)
- 20150607的总结--纪念高考
- 剪花布条
- 1629 - Cake slicing
- 如何将编辑好的TXT转换为PDF文件
- 链表的经典技巧及算法