不赞成包含include/Qt中的头文件

Inclusion of header files from include/Qt is deprecated

本文关键字:文件 Qt 包含 include 不赞成      更新时间:2023-10-16

我最近开始用Qt4编写C++Gui编程。

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

#include <QApplication>
#include <QTextEdit>
int main(int argv, char **args)
{
    QApplication app(argv, args);
    QTextEdit textEdit;
    textEdit.show();
    return app.exec();
}

每次我试图编译这个,我都会得到:

C:Qt4.8.0andrew>qmake -project
C:Qt4.8.0andrew>qmake
C:Qt4.8.0andrew>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
eQtCore" -I"..includeQtGui" -I"..include" -I"." -I"..includeActiveQt" -I"d
ebug" -I"..mkspecswin32-g++" -o debugtutone.o tutone.cpp
In file included from tutone.cpp:1:0:
C:Qt4.8.0includeQtQapplication.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:Qt4.8.0includeQtQpushbutton.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

感谢

由于Qt构建设置中的一个错误,这是一个错误
这不是问题,并且已经记录在Qt错误跟踪器上

运行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