Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] using .pro qmake DEFINES in .h and .cpp file
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vezprog
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vezprog
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved