I have a project I'm working on in Qt creator that requires a third-party library. I want to add the headers to the include path for the project. How do I do this?
4 Answers
If you are using qmake, the standard Qt build system, just add a line to the .pro
file as documented in the qmake Variable Reference:
INCLUDEPATH += <your path>
If you are using your own build system, you create a project by selecting "Import of Makefile-based project". This will create some files in your project directory including a file named <your project name>.includes
. In that file, simply list the paths you want to include, one per line. Really all this does is tell Qt Creator where to look for files to index for auto completion. Your own build system will have to handle the include paths in its own way.
As explained in the Qt Creator Manual, <your path>
must be an absolute path, but you can avoid OS-, host- or user-specific entries in your .pro
file by using $$PWD
which refers to the folder that contains your .pro
file, e.g.
INCLUDEPATH += $$PWD/code/include
-
3Okay. This will work for me just fine. Is there a global setting for include paths? – Nathan Osman May 02 '10 at 03:56
-
2Not that I know of, but that doesn't mean there isn't. I don't see anything in the options that looks like that. – Jason B May 02 '10 at 04:02
-
It isn't working now... I have the following: `INCLUDE_PATH += "C:/users/xxx/documents/projects/xxx/include"` and it's not finding the files in there... – Nathan Osman May 02 '10 at 04:21
-
4Never mind. Your answer mentions `INCLUDE_PATH` but you meant `INCLUDEPATH`. I'll fix your answer :) – Nathan Osman May 02 '10 at 04:23
-
Sorry about that. That's what I get for trying to do it from memory. – Jason B May 02 '10 at 04:55
-
If I want
to be relative, what is it relative to? – Eric Smith Jul 21 '11 at 17:55 -
@EricSmith I believe that it is relative to your current folder. e.g. if you current folder is "C:\Qt\current\" and the include path is "C:\Qt\abc\include" then relative path would be "..\abc\include" I hope this helps! Please correct me if I'm wrong. – zeFree Jan 31 '12 at 15:13
-
8It is better to use the `QMAKE_CXXFLAGS` variables instead, because the `INCLUDEPATH` is buggy(at least at present moment -- QT5). I.e. when I included `INCLUDEPATH += ../../../`, the QT just randomly chosen directory in this path, and the compiler got the option `-I../../../GUI`. – Hi-Angel Aug 01 '14 at 07:12
-
5@Hi-Angel: It seems the `INCLUDEPATH` specified is relative to the build directory, not relative to the directory with the `.pro` as one might easily assume. As shown in my edit to the answer, you can use `$$PWD' to get a clearly defined folder to start the include path with. – ssc Aug 25 '14 at 10:02
-
@ssc thank you for the edit, I'll try. But with disregard of what the Qt supposed to be the root directory — the build one, either with the `.pro` file — it should not convert the path `../../../` to `../../../GUI`. – Hi-Angel Aug 25 '14 at 11:28
-
If my project is at c:\projects\qt\proj1 and I want to include files from c:\projects\qt\proj2 how would I declare the INCLUDEPATH using $$PWD? I tried a number of things and there is no indication that any of them work – galactikuh Aug 26 '16 at 15:34
-
In first time no find header file, but i insist it find. – Delfino Aug 08 '21 at 19:25
For anyone completely new to Qt Creator like me, you can modify your project's .pro file from within Qt Creator:
Just double-click on "your project name".pro in the Projects window and add the include path at the bottom of the .pro file like I've done.

- 8,752
- 12
- 54
- 96
-
9Using absolute file paths is a very bad idea. Always try to use relative file path system. QT is designed for being cross platform. And if you compile same code on a Linux machine, the compiler will fail to find those file names like C:\ Moreover, even if you rename the source folder or move it somewhere else on your own computer, it will still fail, and you will have to edit the .pro file everytime – Shivam Jha May 08 '18 at 12:52
-
Did you manually create the untitled.pro file or it came along when you initiated the project? Completely new to QtCreator so needed some explanation. Thanks. – Aztec-3x5 Oct 30 '21 at 05:43
To add global include path use custom command for qmake in Projects/Build/Build Steps section in "Additional arguments" like this:
"QT+=your_qt_modules" "DEFINES+=your_defines"
I think that you can use any command from *.pro files in that way.

- 81
- 1
- 1
If you use custom Makefiles, you can double click on the .includes file and add it there.

- 639
- 5
- 13