[Qt-interest] qDebug with #ifdef macros ?

Colin S. Miller no-spam-thank-you at csmiller.demon.co.uk
Mon Oct 4 22:11:38 CEST 2010


Rohan McGovern wrote:

> You can try something like this:
> 
>     #ifdef MYDBG
>     #define DBG qDebug()
>     #else
>     #define DBG if (0) qDebug()
>     #endif
> 
> Then in the non-debug case, the code expands to:
> 
>     if (0) qDebug() << "Bonjour Aaron";
> 
> Which is valid, but does nothing at runtime, and generally will not
> cause any machine code to be generated at compile time.

You probably want

#define DBG if (true) {} else qDebug()


incase you try


   if (....)
      DBG << "expression 1\n"
   else
      DBG << "expression 2\n";


#define DBG if (0) qDebug()
wouldn't expand how you want for that if ladder.

HTH,

Colin S. Miller




More information about the Qt-interest-old mailing list