Trouble including Qt Headers
In Qt, some headers are included via the more typical
#include "QtCore/qtheader.h"
But sometimes it uses this notation:
#include <QStr开发者_如何学Pythoning>
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.
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.
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)
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.
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?
精彩评论