[Qt-interest] Any Way To Turn Off qDebug() Expression Evaluation

William Gordon Rutherdale (rutherw) rutherw at cisco.com
Tue Aug 9 00:35:49 CEST 2011


Hi.

I've been finding that in an embedded environment debug statements can
cost a lot of execution time.  Comment out all the qDebug() statements,
and execution efficiency jumps way up.

Example:

qDebug() << "i is" << i << ", huge_list is" << huge_list;

When I look at the Qt source code, it appears that qDebug() is
implemented as an inline function that simply returns a QDebug object.
In order for the statement above to even compile, the compiler has to
generate code to evaluate the expression that takes stuff like huge_list
and convert it into a QDebug() expression, which is basically a stream.
That stream then gets converted to a string (actually char const *) that
is passed down to your handler.

So the problem is that, short of actually commenting out all those lines
of code, even if you make your handler do nothing, the expression is
evaluated up front, costing CPU time.  Of course, sometimes you do want
to see debug show up, so you don't really want to erase all those lines.

Is anyone aware of a facility in Qt that makes it possible to eliminate
all those qDebug() expression evaluations?

-Will




More information about the Qt-interest-old mailing list