Qt code won't compile, not including correct files.

I delving into Qt4 GUI programming, but I can't compile this:

Code:
 #include <QApplication>
 #include <QPushButton>

 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);

     QPushButton hello("Hello world!");
     hello.resize(100, 30);

     hello.show();
     return app.exec();
 }

the error is:

Code:
> gcc -o qt qt.cpp
qt.cpp:1:24: error: QApplication: No such file or directory
qt.cpp:2:23: error: QPushButton: No such file or directory
qt.cpp: In function 'int main(int, char**)':

[BLAH BLAH BLAH]
>

but even when I explicitly give the include paths:

Code:
//#include <QApplication>
#include "/usr/local/include/qt4/QtGui/QApplication"
//#include <QPushButton>
#include "/usr/local/include/qt4/QtGui/QPushButton"

I get this:

Code:
> gcc -o qt qt.cpp
In file included from /usr/local/include/qt4/QtGui/QApplication:1,
                 from qt.cpp:2:
/usr/local/include/qt4/QtGui/qapplication.h:45:37: error: QtCore/qcoreapplication.h: No such file or directory
/usr/local/include/qt4/QtGui/qapplication.h:46:31: error: QtGui/qwindowdefs.h: No such file or directory
/usr/local/include/qt4/QtGui/qapplication.h:47:27: error: QtCore/qpoint.h: No such file or directory
/usr/local/include/qt4/QtGui/qapplication.h:48:26: error: QtCore/qsize.h: No such file or directory

[CLIPPED THE REST, YOU GET THE POINT]

I *know*, I could probably use qmake to build this, but the inquisitive part of me is jumping out; it's still just a C++ program, why can't I compile it?

Thanks for any nudges in the right direction.
 
expl said:
Try compiling like this:
Code:
g++ -I/usr/local/include/qt4/QtGui -I/usr/local/include/qt4 -L/usr/local/lib/qt4 -lQtGui -lQtCore -o qt qt.cpp
If /usr/local/lib/qt4 isn't in a path that [CMD=""]ldconfig[/CMD] checks (extremely likely) the compiled program might not run without preceding the Qt libs with [CMD=""]-Xlinker -rpath /usr/local/lib/qt4[/CMD]. Explicitly naming the Qt libraries by full path-name might be better.
Kevin Barry
 
Even this thread is old, I put this just for knowing the cause of problem.
Code:
#qmake-qt4 -project
#qmake-qt4 
#make
This is for QT4, if you use QT3 try this:
Code:
#qmake -project
#qmake
#make
 
Back
Top