Agh, still getting used to webmail, forgot to cc list on my previous
reply and this one. Just this one should do the trick...

2009/7/3 Pieter Palmers <[email protected]>:
> Something like this might be even easier:
>
> #ifdef __DEBUG__
>        #define IFDEBUG(x) {x;}
> #else
>        #define IFDEBUG(x)
> #endif
>
> which allows to use:
>
> IFDEBUG( qDebug() << "This is some debugging info." );

I think just

qDebug() << "Blah de blah";

and then switch Qt debug messages on or off as appropriate. Qt
provides a way to do this (QT_NO_DEBUG_OUTPUT).

If that control didn't exist, I would still have the test (for whether
or not to display debug messages) inside the debug print function,
rather than force every single debug line to wrap itself in a test
(even a macro). Sure there's an outside chance that if you do
something like...

mydebug("hello");

void mydebug(char *foo) {
 #ifdef DEBUG
 sprintf(stderr, "%s", foo);
 #endif
}

.... that when DEBUG is disabled, a very tiny amount of time is being
wasted calling an empty function. However I'm almost 99% sure that the
compiler would optimise such calls away, so no time would be wasted at
all, and a lot of programmers time saved :)


Any time you're using some kind of structure in a repetitive way, like
#ifdef DEBUG
qDebug()
#endif

or
IFDEBUG( qDebug() );

you're pointlessly causing extra work for yourself and anyone else
working on the code!

> Also note that QT debugging is controlled by QT_NO_DEBUG.

According to what I've read, QT_NO_DEBUG disables Q_ASSERT and
friends. I don't think that's wise.

>From the Qt 4.3 manual:
void qDebug ( const char * msg, ... )

Calls the message handler with the debug message msg. If no message
handler has been installed, the message is printed to stderr. Under
Windows, the message is sent to the console, if it is a console
application; otherwise, it is sent to the debugger. This function does
nothing if QT_NO_DEBUG_OUTPUT was defined during compilation.

So to disable all debug messages at compile time, set QT_NO_DEBUG_OUTPUT,
*not* QT_NO_DEBUG.

If you wished to enable/disable at runtime (eg disabled by default,
can be enabled by adding --debug flag, which could be kinda useful)
you have to install a message handler.

I have a vague sense of deja vu about all this... like maybe I
actually did that at one point, although whether the code ever got
near ready to commit is another matter...

Ben
--
Quextal plays progressive and psychedelic breakbeats and 4/4s for
innerspace journeying and wild dancing.
Free Trips available from http://quextal.com. Search for Quextal on
Facebook to get gig/radio info direct.



-- 
Quextal plays progressive and psychedelic breakbeats and 4/4s for
innerspace journeying and wild dancing.
Free Trips available from http://quextal.com. Search for Quextal on
Facebook to get gig/radio info direct.

------------------------------------------------------------------------------
_______________________________________________
Mixxx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mixxx-devel

Reply via email to