找回密码
 立即注册
收起左侧

编译3-1的mian.cpp报警

3
回复
7988
查看
[复制链接]

尚未签到

来源: 2016-2-4 20:46:27 显示全部楼层 |阅读模式
1Qter豆
买了一本霍老师的快速入门自学。编译3-1有问题。问一下为什么。以下是编译错误报告:
..\mywidget1\main.cpp: In function 'int qMain(int, char**)':
..\mywidget1\main.cpp:5:20: error: variable 'QApplication a' has initializer but incomplete type
     QApplication a(argc, argv);
                    ^
..\mywidget1\main.cpp:11:35: error: invalid use of incomplete type 'class QWidget'
     QWidget *widget = new QWidget();
                                   ^
In file included from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qobject.h:48:0,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qabstractanimation.h:37,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/QtCore:4,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtGui/QtGuiDepends:3,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtGui/QtGui:3,
                 from ..\mywidget1\main.cpp:1:
E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:1314:7: error: forward declaration of 'class QWidget'
class QWidget;
       ^
..\mywidget1\main.cpp:14:11: error: invalid use of incomplete type 'class QWidget'
     widget->setWindowTitle(QObject::tr("鎴戞槸widget"));
           ^
In file included from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qobject.h:48:0,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qabstractanimation.h:37,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/QtCore:4,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtGui/QtGuiDepends:3,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtGui/QtGui:3,
                 from ..\mywidget1\main.cpp:1:
E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:1314:7: error: forward declaration of 'class QWidget'
class QWidget;
       ^
..\mywidget1\main.cpp:17:5: error: 'QLabel' was not declared in this scope
     QLabel *label = new QLabel();
     ^
..\mywidget1\main.cpp:17:13: error: 'label' was not declared in this scope
     QLabel *label = new QLabel();
             ^
..\mywidget1\main.cpp:17:25: error: expected type-specifier before 'QLabel'
     QLabel *label = new QLabel();
                         ^
..\mywidget1\main.cpp:28:13: error: 'label2' was not declared in this scope
     QLabel *label2 = new QLabel(widget);
             ^
..\mywidget1\main.cpp:28:26: error: expected type-specifier before 'QLabel'
     QLabel *label2 = new QLabel(widget);
                          ^
..\mywidget1\main.cpp:36:11: error: invalid use of incomplete type 'class QWidget'
     widget->show();
           ^
In file included from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qobject.h:48:0,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qabstractanimation.h:37,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/QtCore:4,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtGui/QtGuiDepends:3,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtGui/QtGui:3,
                 from ..\mywidget1\main.cpp:1:
E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:1314:7: error: forward declaration of 'class QWidget'
class QWidget;
       ^
..\mywidget1\main.cpp:39:12: error: type '<type error>' argument given to 'delete', expected pointer
     delete label;
            ^
..\mywidget1\main.cpp:40:12: warning: possible problem detected in invocation of delete operator: [-Wdelete-incomplete]
     delete widget;
            ^
..\mywidget1\main.cpp:11:14: warning: 'widget' has incomplete type
     QWidget *widget = new QWidget();
              ^
In file included from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qobject.h:48:0,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qabstractanimation.h:37,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/QtCore:4,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtGui/QtGuiDepends:3,
                 from E:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtGui/QtGui:3,
                 from ..\mywidget1\main.cpp:1:
E:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:1314:7: warning: forward declaration of 'class QWidget'
class QWidget;
       ^
..\mywidget1\main.cpp:40:12: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined
     delete widget;


附件: 您需要 登录 才可以下载或查看,没有帐号?立即注册
回复

使用道具 举报

累计签到:1575 天
连续签到:2 天
2016-2-4 21:03:55 显示全部楼层
这本书的示例代码是基于Qt 4的,请使用书中指定的Qt版本,在论坛下载页面Qt SDK处下载。使用Qt 5会出现很多问题。
回复

使用道具 举报

尚未签到

2016-2-4 21:40:15 显示全部楼层
看来qt5不兼容qt4啊。霍老师再问一个问题。一个仿notepad的项目。里面两个ui。分别是查找和主窗口。这样编的目的主要是编写查找的界面不用语句。而用design。那么怎么将查找对话框中的查找内容用到mainwindow的textedit中?
回复

使用道具 举报

尚未签到

2016-2-16 13:58:39 显示全部楼层
Qt += widgets
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了