简体   繁体   English

不推荐在include / Qt中包含头文件

[英]Inclusion of header files from include/Qt is deprecated

I've recently began working through a C++ Gui Programming with Qt 4 book. 我最近开始使用Qt 4书进行C ++ Gui Programming。

However, I can't get past the first tutorials. 但是,我无法通过第一个教程。

#include <QApplication>
#include <QTextEdit>

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

    QTextEdit textEdit;
    textEdit.show();

    return app.exec();
}

Each time I try to compile this, I get this: 每次我尝试编译它,我得到这个:

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

As I'm new to Qt and fairly new to compiling, I assume the error is on my end. 由于我是Qt的新手并且对编译很新,我认为错误就在我的最后。 Am I declaring the headers wrong or something? 我是否宣布标题错误或其他什么?

My .pro file looks like this: 我的.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

Thanks 谢谢

It's a false error due to a bug in the Qt build setup. 由于Qt构建设置中的错误,这是一个错误的错误。
It's not a problem and has been logged on the Qt bug tracker 这不是问题,已经登录到Qt bug跟踪器

After running qmake -project you should add QT variable in the .pro file. 运行qmake -project您应该在.pro文件中添加QT变量。 Then you can remove these odd HEADERS and SOURCES (and link dynamically Qt libraries to your program): 然后你可以删除这些奇怪的HEADERS和SOURCES(并动态地将Qt库链接到你的程序):

QT += core gui # <-- this line
TEMPLATE = app
TARGET = ProjectNameHere
DEPENDPATH += .
INCLUDEPATH += .

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM