Question

Using CodeLite 5.1 on Ubuntu 12.10:

Created a minimal QTGui app. Built and ran fine.

#include <QApplication> 
#include <QButton> 

were inserted by the wizard in the main.cpp file - no problem. I added:

#include <QString> 

as per QT docs, and pre-processer tells me it can't find QString. I checked the include setting for the projects -

../qt4 

and

../qt4/qt4GUI 

are there correctly. I tried:

#include <qt4/QString>

with different case permutations - all no go.

What's wrong? (Posting this also on CodeLite forum).

Was it helpful?

Solution

While QApplication and QButton are part of the Qt GUI module, QString is part of the Qt Core module. GUI depends on Core, so the Core library is already linked, that's not the problem.

The problem seems that your include path only includes the Qt top level as well as the GUI sub-directory. Qt's header files are structured in modules, one directory for each module. This means that the <QApplication> and <QButton> headers are in ../qt4/qt4GUI and can thus be found by the compiler.

However, QString is placed in ../qt4/qt4Core(1) and thus has either be included as #include <QtCore/QString>(2) which will look in the correct module sub-directory, or by adding the sub-directory to your include paths in the project configuration (recommended), so #include <QString> works too.


(1) I think this should be ../qt4/QtCore, and for Qt GUI ../qt4/QtGui, but you wrote something different in the question...

(2) Iternally in Qt, classes of other modules are included like this, i.e. relative to the Qt top level include path, so if you include a class which uses QString (QApplication being one example), it's working without adding another include.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top