[Qt-interest] qDebug with #ifdef macros ?
Sean Harmer
sean.harmer at maps-technology.com
Sat Oct 2 17:17:39 CEST 2010
On Saturday 02 October 2010 16:11:20 Aaron Lewis wrote:
> Hi,
> I'm trying to implement a custom debug output function with simple
> macros.
>
> #include <QDebug> // Make << operator works , just for
> clarification ;-)
>
> #ifdef MYDBG
> #define DBG qDebug()
> #else
> #define DBG
> #endif
>
> If macro MYDBG is defined , qDebug() will works as usual , else
> it's an empty function.
>
> and if i call it like this :
>
> DBG << "Bonjour Aaron";
>
> It won't even compile , anyone got some ideas to help ? qDebug(
> fmt .. ) isn't really cool somehow ..
No need for any macro magic. Just write your app and use qDebug() as you would
normally. Then when you want to disable the debug output for a release build
say, then just build your app with QT_NO_DEBUG_OUTPUT defined. This is easy to
do by adding something like this to your .pro file:
CONFIG(release, debug|release) {
DEFINES += QT_NO_DEBUG_OUTPUT
}
HTH,
Sean
More information about the Qt-interest-old
mailing list