How to compile Qt4 programs
From ThorstensHome
Home < Tutorials < C Programming Tutorial < How to compile Qt4 programsCompiling Qt4 programs is a real pain if you do not know qmake. I ended up with the compile statement
g++ -I/home/kde-devel/kde/include -I/home/kde-devel/qt-copy/include -I/home/kde-devel/qt-copy/include/Qt -I/home/kde-devel/qt-copy/include/QtGui -L/home/kde-devel/qt-copy/lib -lQtCore -lQtGui main.cpp
Anyway, this was before I got to know qmake. So, here is our hello world project for QT 4:
hello world
Create a directory qttest, proceed in it.
main.cpp
#include <QApplication> #include <QPushButton> int main(int argc, char ** argv) { QApplication qa(argc,argv); QPushButton* qp=new QPushButton("hello world"); qp->show(); return qa.exec(); }
Build and run it:
qmake -project && qmake && make && ./qttest
There is no explanation whatsoever why you need to call
qmake -project && qmake
in order to get a Makefile that can be used by the command
make
to finally build something. But it works :)

