[Development] QLog ( Work on qDebug and friends)

Lincoln Ramsay lincoln.ramsay at nokia.com
Mon Feb 13 01:33:11 CET 2012


On 02/11/2012 01:44 AM, ext kai.koehne at nokia.com wrote:
> However, adding yet another 'keyword' to the framework has a price,
> especially since the difference between
> 'qDebug(QMessageLogContext("MyCategory"))'<< and a
> 'qLog("MyCategory")<< ' is subtle.

We tried that but while this difference is subtle to the eye, it's a 
huge difference to the implementation.

qDebug is currently an argument-less macro that expands to the name of a 
function. Before message logging it was just a plain old function. 
Overloading means that qDebug("message") and qDebug() << "message" both 
work.

Since we can't have a macro func with 0, 1 or many arguments, we can 
only add a new overload for qDebug(category) << "message" but if we do 
this, there is nowhere to put the "do nothing quickly" logic.

Expanding to this is always going to be slow:
func(category) << "args" << expensive();

We need to expand to this to be fast:
if (do_nothing) /*NOP*/; else func(category) << "args" << expensive();

Thus we cannot overload qDebug.

qLog is just a name. It's the name this code had when it was in Qtopia 
but it's hardly important if it keeps this name. It would be nice to 
focus on the implementation of the feature to make sure it is sound 
before we worry overly much about what to call it :)

-- 
Lincoln Ramsay - Senior Software Engineer
Qt Development Frameworks, Nokia - http://qt.nokia.com/



More information about the Development mailing list