Reputation: 48916
I'm new to Qt
, and trying to compile and run this Qt program I typed from the Programming with Qt
book:
#include <qapplication.h>
#include <qlabel.h>
int main(int argc, char *argv[])
{
QApplication myapp(argc, argv);
QLabel *mylabel = new QLabel("Hello",0);
mylabel->resize(120,30);
myapp.setMainWidget(mylabel);
mylabel->show();
return myapp.exec();
}
When I do this: C:\Qt\2010.05\qt>gcc label.cc
on the Qt command prompt
, I get the following:
label.cc:1:26: error: qapplication.h: No such file or directory
label.cc:2:20: error: qlabel.h: No such file or directory
label.cc: In function 'int main(int, char**)':
label.cc:5: error: 'QApplication' was not declared in this scope
label.cc:5: error: expected ';' before 'myapp'
label.cc:6: error: 'QLabel' was not declared in this scope
label.cc:6: error: 'mylabel' was not declared in this scope
label.cc:6: error: expected type-specifier before 'QLabel'
label.cc:6: error: expected ';' before 'QLabel'
label.cc:8: error: 'myapp' was not declared in this scope
Why is that? Is it correct the way I did for compiling a Qt
program?
Thanks.
Upvotes: 1
Views: 4716
Reputation: 461
Add
QT += widgets
to your pro file, and
#include <QtWidgets>
to your main.cpp
Upvotes: 0
Reputation: 999
Qmake can generate some default project file like this:
qmake -project
qmake
make
First line generates project file, second generates makefile from the project file and make builds the project.
Upvotes: 7
Reputation: 6129
You're missing the include path to where you have the Qt headers.
-Ipath_to_qt/include
Upvotes: 2
Reputation: 3686
To build with the Qt system you need to use the meta object compiler, moc; maybe the user interface compiler, uic and define paths to the include files and link to the Qt libraries.
The usual way to do this is using qmake
as provided by Qt. You must write a project file for qmake. This is many times easier than writing a command line or makefile.
Upvotes: 2