Qt: passing variables to subprojects

The structure of my project is as follow:

Proj
Proj.pro
--subProj
--subProj.pro
----subsubProj
----subsubProj.pro

Is there a way i can instance a global variable in subProj.pro and call it en eg subsubProj.pro like:

Proj.pro:

GLOBAL_VAR = true

subsubProj.pro:

message($$GLOBAL_VAR)

Update

Maybe I should more precise with my problem.

The usual behavior in Qt Creator when you right-click on Proj and choose "Build project"Proj"" is that qmake Proj.pro gets invoked then qmake subProj.pro and then subsubProj.pro

What I want to achieve is:

  • When i build the project "Proj" only Proj.pro and subProj.pro get invoked (NOT subsubProj.pro)
  • BUT: When i build the project "subProj" the invoked files are subProj.pro and subsubProj.pro
  • You achieve 1) by adding to subProj.pro:

    TEMPLATE = subdirs
    dont_invoke_subsub{
    SUBDIRS = subsubProj
    }
    

    In this case when you do qmake Proj.pro 1) is fulfilled. BUT when you do qmake subProj.pro the subsubProj doesnt get built neither.

    So my idea was to hand over a variable from Proj to subProj.

    Proj.pro:
    
    GLOBAL_VAR = true;
    

    and subProj retrieves this variable:

    subProj.pro
    
    TEMPLATE = subdirs
    equals(GLOBAL_VAR, true){
       # do nothing because Proj.pro invokes you
    }
    else {
       # invoke qmake subsubProj.pro
       SUBDIRS = subsubProj
    }
    

    I managed to do that with the include(...) command via config files.

    An other way (but more limited) is to use CONFIG+=GLOBAL_VAR in the qmake arguments list. That technique is quite useful for 'master' switchs.

    But with both of them you can't change the GLOBAL_VAR during the pre-build process (qmake step) ...

    链接地址: http://www.djcxy.com/p/53606.html

    上一篇: 如何在Android ImageView中显示加载动画?

    下一篇: Qt:将变量传递给子项目