0 down vote favorite


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.

Make sure that Qt is on your path, or start up the "Qt 4.x.x Command Prompt" from the start menu. Switch to your code directory and type:

qmake -project 
(which sets up the project folders)
qmake hello.pro
(or whatever you want to name the makefile, but I think it must be .pro
make

This info is probably tucked away in a corner somewhere within the book you are reading. They should express it more clearly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.