Does Qt offer a (guaranteed) debug definition?

▼魔方 西西 提交于 2019-12-03 05:30:39

问题


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

#ifdef QT_DEBUG
// do something
#endif

Basically like Q_ASSERT but for more complex tests.

I can't seem to find any documentation which says that the Qt framework guarantees to define a debug macro. If there isn't, what would be a sensible unofficial way to implement this feature project wide?


回答1:


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.




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/8801584/does-qt-offer-a-guaranteed-debug-definition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!