Reputation: 7338
I've recently began working through a C++ Gui Programming with Qt 4 book.
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. Am I declaring the headers wrong or something?
My .pro file looks like this:
######################################################################
# 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
Upvotes: 3
Views: 5716
Reputation: 3687
After running qmake -project
you should add QT
variable in the .pro file. Then you can remove these odd HEADERS and SOURCES (and link dynamically Qt libraries to your program):
QT += core gui # <-- this line
TEMPLATE = app
TARGET = ProjectNameHere
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += tutone.h
SOURCES += tutone.cpp \
tutthree.cpp \
Upvotes: 1
Reputation: 96119
It's a false error due to a bug in the Qt build setup.
It's not a problem and has been logged on the Qt bug tracker
Upvotes: 4