[Qt-interest] qDebug with #ifdef macros ?

Constantin Makshin cmakshin at gmail.com
Sat Oct 2 17:50:18 CEST 2010


It doesn't compile because when MYDBG isn't defined, your line
DBG << "Bonjour Aaron";
becomes
<< "Bonjour Aaron";

And qDebug(fmt, ...) is, IMHO, better because it can be completely removed during compilation in release mode, unlike the stream version that leaves the code (it still prints debugging information, but uses a dummy stream and therefore you don't see it) and data (in your case it's "Bonjour Aaron" string) in the final binary.

On Saturday 02 October 2010 19: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 ..
> 
>     Many thanks !



More information about the Qt-interest-old mailing list