Home > Software engineering >  How qt find <Qxxx/qxxx.h>?
How qt find <Qxxx/qxxx.h>?

Time:10-08

In Qt 6.4.0, we can use such code to include qt components:

#include <QtCore/qchar.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qbytearrayview.h>
#include <QtWidgets/qtwidgetsglobal.h>

But I found that the real paths of those .h file are NOT under such folder like QtCore, QtWidgets etc. , actually most of them are under such directory: /Users/tony/Qt/6.4.0/macos/lib/QtXXX.framework/Headers/qtxxx.h

I'm wondering that since QtCore is not the real path but Headers, Shouldn't we write #include "Headers/qtxxx.h" ? how can #include <QtCore/qchar.h> such path works?

CodePudding user response:

Using the -I argument

You have to tell to your compiler which directory you want to include to find the headers properly. For example in clang and gcc you can use this directory as -I argument, like this:

clang   yourprogram.cpp -I /Users/tony/Qt/6.4.0/macos/lib/QtXXX.framework/Headers/

And in your source code you will write includes at this way:

#include "QtCore/qchar.h"
#include "QtCore/qbytearray.h"
#include "QtCore/qbytearrayview.h"
#include "QtWidgets/qtwidgetsglobal.h"

Note it uses " " instead < >, this means you are finding the included files relative to your compile options instead of your system.

Although this works, it's recommended to use relative paths of your project to point headers directories.

CodePudding user response:

It's been solved: This phenomenon only shows on MacOS since MacOS uses "framework" to organize a set of lib and headers, which can be parsed by the clang-module name to the realpath.

  • Related