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

Thiago Macieira thiago at kde.org
Tue Aug 9 01:07:18 CEST 2011


On Monday, 8 de August de 2011 17:35:49 William Gordon Rutherdale wrote:
> 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.

Take a better look.

> 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?

Yes. #define QT_NO_DEBUG_STREAM or #define QT_NO_DEBUG_OUTPUT. They're slightly 
different, the latter is what you want.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110809/8a47b67b/attachment.bin 


More information about the Qt-interest-old mailing list