2

In Qt, some headers are included via the more typical

#include "QtCore/qtheader.h"

But sometimes it uses this notation:

#include <QString>

I'm not sure what the difference is or why this done. Regardless, I'm having trouble including headers that themselves use the latter notation. Any ideas?

Thanks.

glutz
  • 1,889
  • 7
  • 29
  • 44
  • 2
    post the actual error messages, the command line you use, and the location of the headers on your machine. The first example you show is _not_ typical. – Mat Jul 05 '11 at 18:48

4 Answers4

4

This is odd behaviour you describe. Doing

#include <QString>

should "just work" as it's pretty much the standard way of doing it.

The only thing I can think of is that you've overwritten the QT variable in your project file. For example, if you do

QT=opengl

to get at the OpenGL module instead of

QT+=opengl

then you will get the behaviour you describe.

Troubadour
  • 13,334
  • 2
  • 38
  • 57
1

As you gave little information about the error and what kind of development environment you are using, the following thing could be an issue if you are not using .pro files. If you are actually using .pro files this might not be relevant for you:

If you are using e.g. Visual Studio rather than Qt Project files and you only include $(QTDIR)\include, then you will have to write

#include <QtCore/QObject>
#include <QtGui/QWidget>

and so on. This is because Qt's include directory has the files in subfolders "QtCore", "QtGui" etc.

If you don't want to add the QtCore or QtGui or whatever in your includes, you would have to include $(QTDIR)\include\QtCore, $(QTDIR)\include\QtGui etc

(Note that I'm not 100% sure about the include path, can't look it up on this machine)

Tim Meyer
  • 12,210
  • 8
  • 64
  • 97
0

In C and C++, when you use double-quotes, it means: Search the same directory as this file. When you use <> it means: Search the include paths.

With gcc you can add include paths with the -I command line parameter.

Are you using Qt Creator and qmake? If you are, edit the .pro like in this question/answer: How to add include path in Qt Creator?

Community
  • 1
  • 1
Vinicius Kamakura
  • 7,665
  • 1
  • 29
  • 43
0

I don't know what is causing you troubles as you don't specify sufficient details. Anyway, in C++ when you include using <>, you mean you want to search in the include path. You can specify the include path and add some directories to it in Qt by adding a:

INCLUDEPATH += ...

in the project file. If you use the double quotes you ask to add the current source directory to the include path.

So you'll see:

#include <QString>

because in your system include path there should be a file named QString. Inside it there is indeed:

#include "qstring.h"

which is in fact, usually in the QtCore directory.

Luca Carlon
  • 9,546
  • 13
  • 59
  • 91
  • There should be no need to add anything to `INCLUDEPATH` to get at Qt headers. – Troubadour Jul 05 '11 at 21:38
  • I didn't say that indeed. I just said that new include paths may be added using that directive. The question itself, with the word "regardless" made me think the author was not referring to problems including Qt headers. – Luca Carlon Jul 05 '11 at 22:13
  • 1
    I'm using gcc on the cmd line, not qt creator. – glutz Jul 06 '11 at 13:19
  • @glutz, knowing you are using gcc on the command line is an important detail. If you are going to do that, you absolutely must learn about how to specify include paths, or you'll never get anywhere with using Qt, or indeed many, many other libraries. For Qt, I definitely recommend using a build system (like QMake) to help you. – Caleb Huitt - cjhuitt Jul 07 '11 at 15:27