Qt World Summit: Register Today!

Setting global variable in subdirs template

  • I have a project based on subdirs template.
    Each of the subprojects is having a DESTIDR statement to a central folder. Now I try to change the destination temporily to another folder.
    I have thought about setting DESTDIR in subdirs .pro and remove the individual DESTDIR folders.

    However, apparently any variable set in the subdirs .pro is not accessible in the individual .pro files.
    Any ideas how to do this?

  • Moderators

    Try setting your own variable and then eval it for each subproject, e.g.:

    MY_OUT_PATH = /my/output/path
    TEMPLATE = subdirs
    # ...

    and then (for each subproject):


    If that doesn't work you could try setting an environment variable instead when qmake's run, e.g. (in the subproject files):


    which requires you to run qmake with that environment set:

    $ MY_ENV_PATH=/some/destination/path /path/to/qmake project.pro

    Hope that helps.
    Kind regards.

  • @kshegunov

    I had tried already the first option and it does not work.

    Going through the environment does work. It looks a bit strange.

  • Lifetime Qt Champion


    IIRC, you can put these variables in file named .qmake.cache at the root of your project.

  • @SGaist

    Yes, you are right.

    I had misinterpret "root of your project" at first. .qmake.cache has to be in one of the parent directories as the documentation says. If it is on the same level as the .pro file, it will not work.

    Basically the environment approach and the .qmake.cache may be used.

  • Lifetime Qt Champion

    My bad ! It was .qmake.conf that you can use for your common variables.