问题
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