从include/Qt中包含头文件已经被弃用

3

我最近开始学习一本关于使用Qt 4进行C++ Gui编程的书。

然而,我无法通过第一个教程。

#include <QApplication>
#include <QTextEdit>

int main(int argv, char **args)
{
    QApplication app(argv, args);

    QTextEdit textEdit;
    textEdit.show();

    return app.exec();
}

每次我尝试编译这个代码,都会遇到以下错误提示:
C:\Qt\4.8.0\andrew>qmake -project

C:\Qt\4.8.0\andrew>qmake

C:\Qt\4.8.0\andrew>make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Qt/4.8.0/andrew'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -
DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -
DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\includ
e\QtCore" -I"..\include\QtGui" -I"..\include" -I"." -I"..\include\ActiveQt" -I"d
ebug" -I"..\mkspecs\win32-g++" -o debug\tutone.o tutone.cpp
In file included from tutone.cpp:1:0:
C:\Qt\4.8.0\include\Qt\Qapplication.h:3:10: warning: #warning "Inclusion of head
er files from include/Qt is deprecated." [-Wcpp]
In file included from tutone.cpp:2:0:
C:\Qt\4.8.0\include\Qt\Qpushbutton.h:3:10: warning: #warning "Inclusion of heade
r files from include/Qt is deprecated." [-Wcpp]
tutone.cpp: In function 'int qMain(int, char**)':
tutone.cpp:11:7: error: 'class QApplication' has no member named 'setMainWidget'

mingw32-make[1]: *** [debug/tutone.o] Error 1
mingw32-make[1]: Leaving directory `C:/Qt/4.8.0/andrew'
mingw32-make: *** [debug] Error 2

作为一个新手,我对Qt和编译都不是很熟悉,我认为错误出在我的代码中。我是不是声明头文件有误了?我的.pro文件如下:
######################################################################
# Automatically generated by qmake (2.01a) Thu Jan 19 12:41:21 2012
######################################################################

TEMPLATE = app
TARGET = 
DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS += tutone.h \
           C:/Qt/4.8.0/include/Qt/Qapplication.h \
           ../include/QtGui/qapplication.h \
           ../src/gui/kernel/qapplication.h \
           C:/Qt/4.8.0/include/Qt/Qpushbutton.h \
           ../include/QtGui/qpushbutton.h \
           ../src/gui/widgets/qpushbutton.h
SOURCES += tutone.cpp \
           tutthree.cpp \
           ../src/gui/kernel/qapplication.cpp \
           ../src/gui/widgets/qpushbutton.cpp

谢谢


1
你尝试过只使用 #include <QtCore>#include <QtGui> 吗?我还没有尝试过4.8,但他们可能只是希望你按模块来工作。 - Samuel Harmer
我尝试过了,结果一样。我正在尝试编译的这个特定教程直接来自Qt网站。但是有一件事情我应该提一下,在Qt Creator中它说我的两个头文件都不存在。我是否需要定义头文件的完整路径? - Andrew De Forest
如果在线上有确切的教程链接,您能否添加链接?同时请提供您的 .pro 文件内容。 - Samuel Harmer
http://doc.qt.nokia.com/4.7/gettingstartedqt.html,我会在我的原始问题中发布.pro文件。 - Andrew De Forest
一个小问题是使用与您版本对应的教程。等下载完毕,我会试着在4.8上构建它。 - Samuel Harmer
2个回答

4

这是由于Qt构建设置中的一个错误而造成的虚假错误。
这不是问题,并已在Qt错误跟踪器上记录。


1
在运行qmake -project之后,您应该在.pro文件中添加QT变量。然后,您可以删除这些奇怪的HEADERS和SOURCES(并动态链接Qt库到您的程序):
QT += core gui # <-- this line
TEMPLATE = app
TARGET = ProjectNameHere
DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS += tutone.h 
SOURCES += tutone.cpp \
        tutthree.cpp \

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接