View Full Version : problem with include files

22nd December 2006, 19:35
Hello, this is my first post and as usual it starts with a problem.
This is my first day of looking at QT (QT4) and I'm quite excited about it but I haven't really got very far.
(I'm using Ubuntu Linux and QT4 which I downloaded yesterday to evaluate.)
I wonder if anyone can help.
My problem is that when I compile a simple hello world I get: "QApplication: No such file or directory" and the same for the QPushButton file header.

The cpp file has:

#include <QApplication>
#include <QPushButton>

The code is very simple - I copied from a tutorial.

My PATH variable includes the following:

Both of the header files are actually in .../include/QtGui/ so for the for the compiler to find them I would imagine that that path should be in $PATH - but that seems like far too much work really. So I must be missing something that enables the complier to look in sub directories. Or perhaps I'm missing something else that is obvious to everyone other than me.
Any help will be greatly appreciated.
thanks a lot


22nd December 2006, 20:39

did you use qmake to set up a project file as described in the same tutorial?

If not run "qmake -project" followed "qmake" and then "make" in the directory your project is in. This should work without setting up any path to the header files.

Else if the project doesn't work try to tell the compiler explicit where it finds the headers by appending

-I/usr/local/Trolltech/Qt-4.2.2/include/QtCore -I/usr/local/Trolltech/Qt-4.2.2/include/QtGui -I/usr/local/Trolltech/Qt-4.2.2/mkspecs/linux-g++ -I/usr/local/Trolltech/Qt-4.2.2/include

to your g++ calls. When you link everything together you also need to specify which libraries to use for this. Append
-L/usr/local/Trolltech/Qt-4.2.2/lib -lQtGui -lQtCore

Now it should compile and link without errors.

If you get linker errors when you start the application you need to set the path to the Qt libraries in the LD_LIBRARY_PATH environment variable.

You can also add the above includes to the CPLUS_INCLUDE_PATH variable. Btw. the PATH variable should only contain paths to binaries. The compiler doesn't look there for anything.

Hope it helps.

22nd December 2006, 20:44
You only need to add the path to the Qt's bin directory to locate qmake, moc and other Qt tools (others are not needed) to the PATH env variable:


Are you using qmake? If Qt is installed correctly, (for a simple project) it should be as simple as:

$ qmake -project
$ qmake
$ make