⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

QtCreator and environment variable in INCLUDEPATH

  • Hi everyone.

    I am facing a problem while porting my project from Qt 4.7.4/QtCreator 2.6.2 to Qt 4.8.6/QtCreator 3.6.1.
    We are using environment variable a lot, to add path in INCLUDEPATH of our .pro files. We often add multiple path in there environment variables.

    Since I try to use QtCreator 3.6.1, the completion does not work anymore for include that are defined in the INCLUDEPATH using theses environment variable.

    Let's take an exemple :

    I have a test project, with an external class, defined in a .h and .cpp files from a folder /home/myClass.
    I have an environment variable (ENV_VAR) defined to /home/myClass

    In the .pro file of my test project who is stored in /home/myProject I do


    This works fine. But now, if I put two path in the ENV_VAR (eg: /home/myClass /home/myOtherClass), QtCreator does not resolve the includes anymore and completion does not work either. By the way QMake works, as I can compile the project.
    This works with QtCreator 2.6.2.

    If i do

    INCLUDEPATH += /home/myClass /home/myOtherClass

    it works in both QtCreator versions.

    I hope I was clear enough, does anyone have a clue on wath's going on here ?

    Thanks !

  • Lifetime Qt Champion


    Sounds like it might be a regression. Can you create a minimal sample project that can reproduce this ?

  • @SGaist Yes I can do this :)

    Download File

    You will have to define an environment variable named ENV_VAR to '../myClass' in the project configuration, compilation environment.
    If you do this, you will be able to CTRL+Clic on myClass.h to open the header.

    Now if you add something before or after in the ENV_VAR like :

    ENV_VAR=/this/break/completion ../myClass


    ENV_VAR=../myClass /this/break/completion

    even if the path is valid, the completion does not work anymore.

    Thanks !

  • Lifetime Qt Champion

    What I suspect is that the handling of spaces in the environment variable has changed.

    If you write INCLUDEPATH += "/this/break/completion ../myClass", it will also "break".

    I can't comment whether this change can be considered a bug since you would usually quote strings that you put in an environment variable if it contains space(s) and use a separator like : when you want to have several values.

  • My problem is that none of the solutions works, i can't have multiple path in one environment variable.

    Why Creator does not replace the $$(ENV_VAR) whit its content ? Because this will work, and was working in previous version.
    It means that

    INCLUDEPATH = /this/break/completion ../myClass


    ENV_VAR=/this/break/completion ../myClass

    does not behave the same way.
    For me it's a problem, and i can't find a workaround to bypass this !

    Nota :
    If i use a variable in the pro file instead of an environment variable it works... Like :

    TEST_VAR = /this/break/completion ../myClass

  • Lifetime Qt Champion

    It's not Qt Creator, it's qmake. Anyway, I suspect that the content is quoted now.

    Try with:

    for (var, $ $list($ $(ENV_VAR))) {
        INCLUDEPATH += $ $var

    [edit: fixed code sample, remove spaces between $ in real .pro file]

  • I can't get this to work either. :(

    By the way how can it be QMake and not QtCreator as the compilation work, only the completion in IDE does not work.

  • Lifetime Qt Champion

    For qmake, i was referencing the environment variable handling.

    Note that I forgot the double $ problem. I've fixed the sample, can you retry with that new version ? It's working correctly on Qt Creator 3.5.1

  • Okay this works.

    It's not an elegant solution for us, as we have a lot of pro file, with a lot on environment variable used in INCLUDEPATH in these. It's sad that this particular behaviour has changed in new versions. We will figure out how to make things works for us.

    Thanks a lot for your help !

  • Lifetime Qt Champion

    One alternative would be to create your own function that does that parsing and use it like:

    INCLUDEPATH += $ $parseEnvVariable(ENV_VAR)

    That way if you change the formatting of your environment variables you only have to update the code in one place.