当前位置: 代码迷 >> QT开发 >> 《C++ GUI with QT4》
  详细解决方案

《C++ GUI with QT4》

热度:329   发布时间:2016-04-25 04:13:40.0
《C++ GUI with QT4》求救
各位大牛,《C++ GUI with QT4》的第二章第三节,用QT Designer快速设计对话框,里面讲到用QT Designer设计一个Form,保存为gotocell.ui,然后用纯文本编辑器写一个main.cpp。
接着运行qmake -project; qmake gotocell.pro 
我的是windows的系统。
这是原文:
===============================================
将此对话框保存到gotocell文件夹中,取名gotocelldialog.ui,在此文件夹中创建一个main.cpp文件,包含如下内容: 

#include <QApplication>
#include <QDialog>

#include "ui_gotocelldialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Ui::GoToCellDialog ui;
QDialog *dialog = new QDialog;
ui.setupUi(dialog);
dialog->show();
return app.exec();
}
现在运行qmake命令(qmake -project; qmake gotocell.pro)创建makefile文件。Qmake可自动检测到用户界面文件gotocelldialog.ui,并在makefile中添加合适的UIC(user interface compiler)规则语句。UIC工具最终将gotocelldialog.ui文件转换为标准C++代码,存于ui_gotocelldialog.h文件中

我在论坛上找到这张帖,用过两种方式编译这个例子,第一种直接add书中的ui文件到新的工程,在同个目录下add新的main文件,main内容跟书里一样;第二种在开始菜单找到Qt 命令行工具,打开控制台窗口,进入main.cpp所在目录,敲入qmake -project回车,作用是生成.Pro工程文件,再敲入qmake XXX.pro(XXX与目录名有关)回车,生成相关MakeFile文件,再敲入mingw32-make,回车,会编译并连接生成一个可执行文件,再在creator打开工程编译。这两种方法都会报错如下:
..\gotocelldialog\main.cpp: In function 'int qMain(int, char**)':

..\gotocelldialog\main.cpp:8: error: 'GoToCellDialog' is not a member of 'Ui'

..\gotocelldialog\main.cpp:8: error: expected ';' before 'ui'

..\gotocelldialog\main.cpp:10: error: 'ui' was not declared in this scope


求各位大牛指教,在此十分感谢!!!


------解决方案--------------------
..\gotocelldialog\main.cpp:8: error: '' is not a member of 'Ui'
Ui下没有GoToCellDialog
..\gotocelldialog\main.cpp:8: error: expected ';' before 'ui'
少;
..\gotocelldialog\main.cpp:10: error: 'ui' was not declared in this scope
ui未定义
------解决方案--------------------
http://hi.baidu.com/gabmars/item/19fb753bbf0444cf392ffaaa
  相关解决方案