0

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).

Vector
  • 10,879
  • 12
  • 61
  • 101
  • 1
    Just out of curiosity (I don't want to say you shouldn't use CodeLite): Why not using QtCreator? Do you miss a feature? – leemes Apr 18 '13 at 16:54
  • 2
    `QString` is then probably in `../qt4/qt4CORE`. QString is part of the Core module, where as QApplication and QButton are in Qt Gui. You should add this directory to your include paths. – leemes Apr 18 '13 at 16:57
  • @leemes - I just find CodeLite a lot more comfortable to use. Clean, simple UI. Also not so bound up with QT - I prefer something completely generic - and I like to support/use the project - it's about the only decent openSource generic C++ out there at this point. – Vector Apr 18 '13 at 18:46
  • @leemes - qt4CORE sounds right - I think that's what pyQT always uses - but I can't test now. Too bad the QT docs don't include that in the entry for QString. Post it as an answer. – Vector Apr 18 '13 at 18:49
  • QtCreator is a generic C++ IDE. Of course, it aims developing mainly Qt applications, but I use it for every C++ project, whether with Qt or not. But again: Of course it's your free choice ;) I just didn't know this IDE so I wanted to know if it has something really cool feature missing in QtCreator. – leemes Apr 18 '13 at 19:03
  • 1
    the complete include in Qt4 would be #include – Frank Osterfeld Apr 18 '13 at 19:03
  • @FrankOsterfeld Also an option (see also my answer), but Qt developers recommend to add the include path of the modules used in a project. Their idea is to `#include ` if you want to use `Class` in your project, for simplicity. – leemes Apr 18 '13 at 19:05
  • @leemes: I know you can use QTCreator for generic C++ too. It's a very good IDE.I just find it cluttered and not too intuitive-'just me'. I haven't gone down the list but I think CodeLite does have more options for using things like GT++ and WXWidgets, more tool chains etc. But haven't done an in depth study of either. I doubt if you're missing anything so cool in CodeLite-they take the KISS approach-it's light and clean-which is why I like it. Still missing a lot of conveniences-key stroke short cuts, other little stuff-like most true open source tools. QTCreator definitely more 'polished'. – Vector Apr 18 '13 at 19:14

1 Answers1

1

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.

leemes
  • 44,967
  • 21
  • 135
  • 183
  • Both worked: and adding ../qt4/QtCore in the include paths. 1-I typed 'GUI' but it should have been 'Gui'. 2 - that's what I thought too - still not sure what's going on, but your answers are correct. Tnx – Vector Apr 18 '13 at 23:21