[SOLVED] using .pro qmake DEFINES in .h and .cpp file



  • Hi,

    This is kind of new grounds for me in Qt in which I haven't really played around with QMake parameters very much and after reading through the documentation, there is not really an example of what I am trying to accomplish...and I feel like I am just missing a simple step.

    Currently I am using a subdir project that has a configuration.pri included by some of the sub projects. What I am trying to accomplish is to use DEFINES in the .pri as preprocessor defines for conditionals in my code.

    So say I have a define named SETUP_ROUTINE. So in my .pri I have:
    @

    run setup routine if define is enabled

    DEFINES += SETUP_ROUTINE
    @

    In one of my .cpp files (which the .pro of the sub dir project includes coniguration.pri) I would like to do the following:

    @
    // check if configuration is enabled
    #ifdef SETUP_ROUTINE
    if (foo->doSetup()) // do setup routine
    qDebug() << "setup routine completed";
    #endif
    @

    For some reason, when running my code with the DEFINE commented out, the foo->doSetup() keeps getting called. You can tell that the system recognizes that the define is not there because the creator highlights the background of the conditional statement correctly.

    Am I missing something here?


  • Lifetime Qt Champion

    Hi,

    Commenting the DEFINES in your pri file doesn't necessarily trigger the recompilation of all the files using that define. Depending of the IDE you use, you might have to "touch" the files using that define so that they get rebuild.



  • That was it. In my case, I run a full clean and re-make/build on the projects that included the configuration.pri.

    Not sure how I missed that, but it works like a charm.

    Thank you again.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.