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] [QMake] How to conditionally compile code depending on debug/release
QtWS25 Last Chance

[SOLVED] [QMake] How to conditionally compile code depending on debug/release

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 7.8k Views
  • 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.
  • S Offline
    S Offline
    sylvaticus
    wrote on last edited by
    #1

    In a large C++/Qt/QMake/qtcreator project I would like to perform some tests, but only when I am compiling with the debug flag.

    Is there a way to tell g++ that some small parts of the code have to be compiled only in debug mode ?

    I have tried things like this but without success..

    @
    #ifdef DEBUG
    cout << "We are in Debug" << endl;
    #else
    cout << "We are in Release" << endl;
    #endif
    @

    I guess I need to put the "DEBUG" flag somewhere in the QMake project, like:
    @
    CONFIG(release, debug|release) {
    TARGET = ffsm
    }
    CONFIG(debug, debug|release) {
    TARGET = ffsm_debug
    }
    @

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

      Hi and welcome to devnet,

      You can use

      @#ifdef QT_DEBUG
      // My debug related code
      #else
      // Release only code
      #endif@

      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
      • S Offline
        S Offline
        sylvaticus
        wrote on last edited by
        #3

        thank you, it works the expected way...

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

          You're welcome !

          A little side note since you want do tests, you might be interested by the QTest framework

          Happy coding !

          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

          • Login

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