PDA

View Full Version : qDebug macro substitution



the_bis
14th November 2006, 15:18
I want to create a macro that expands to qDebug, so I suppress the qDebug output in release build.
How can I do it correctly?

I tried with:



#ifdef MY_DEBUG
#define QDEBUG(x) qDebug(x)
#else
#define QDEBUG(x)
#endif


but I have a problem with multiple qDebug parameters like:



qDebug ( "ENTER in DeviceConfiguration = %s\n", moduleName.ascii() );


Any help?
Thanks,
the_bis

drkbkr
14th November 2006, 17:18
This works for me (using TRACE instead of QDEBUG, of course):


#ifdef DEBUG
#define TRACE qDebug
#else
#define TRACE(fmt,arg...) ((void)0)
#endif

the_bis
15th November 2006, 09:31
Yes! It works!

My project.pro is now:



[...]
CONFIG += qt warn_on debug
[...]
debug {
DEFINES += MY_DEBUG
}
[...]


and my project.cpp is now:



#ifdef MY_DEBUG
#define QDEBUG qDebug
#else
#define QDEBUG(fmt,arg...) ((void)0)
#endif
[...]
QDEBUG ( "Value now is %s\n", varResult.ascii() );
[...]


Thank you very much,
the_bis