Does Qt offer a (guaranteed) debug definition?

前端 未结 3 772
后悔当初
后悔当初 2021-02-01 14:26

Does anyone know an officially supported way to include debug-build only code in Qt? For example:

#ifdef QT_DEBUG
// do something
#endif

Basica

相关标签:
3条回答
  • 2021-02-01 14:38

    For check debug mode:

    #ifdef QT_DEBUG
        //Some codes
    #endif
    

    For check release mode:

    #ifndef QT_DEBUG    //<== Please note... if not defined
        //Some codes
    #endif
    
    0 讨论(0)
  • 2021-02-01 14:43

    Qt defines QT_NO_DEBUG for release builds. Otherwise QT_DEBUG is defined.

    Of course you are free to specify any DEFINES in your .pro files and scope them for either debug or release.

    0 讨论(0)
  • 2021-02-01 14:46

    An alternative is to write in your project file something like:

    debug {
      DEFINES += MYPREFIX_DEBUG
    }
    release {
      DEFINES += MYPREFIX_RELEASE
    }
    

    Then you will not depend on the Qt internal definition.

    0 讨论(0)
提交回复
热议问题