Detect if qt is running a debug build at runtime

If you just want to test whether you are running a debug or release build of your application, use QT_DEBUG:

#ifdef QT_DEBUG
  qDebug() << "Running a debug build";
#else
  qDebug() << "Running a release build";
#endif

Though this obviously uses the pre-processor, rather than checking at runtime. I'm a bit confused as to why you've specified that you want to make this check at runtime, seeing as the decision to build with or without debug capability can only be made prior to compiling...

I'm not aware of any easy way in Qt4 to check whether the Qt library you're linking against has been built with debugging enabled (though I did notice that this looks to be changing in Qt5 with the addition of QLibraryInfo::isDebugBuild()).


Both hints in accepted answer are true. There is one side effect with Qt5 on macOS. By Default, frameworks use a release version of it's library and the result of this method will be always 'false' value.

Tags:

Kde

Qt

Qt4

Pyqt