[Development] Let's get rid of qDebug/qWarning/qCritical!

Koehne Kai Kai.Koehne at digia.com
Wed Jan 8 10:12:39 CET 2014


> -----Original Message-----
> From: Giuseppe D'Angelo [mailto:dangelog at gmail.com]
> Sent: Wednesday, January 08, 2014 9:54 AM
> To: Koehne Kai
> Cc: development at qt-project.org
> Subject: Re: [Development] Let's get rid of qDebug/qWarning/qCritical!
> 
> On 8 January 2014 09:35, Koehne Kai <Kai.Koehne at digia.com> wrote:
> > - Current #ifdef's, environment variables etc should be replaced with
> > an unconditional qCDebug/qCWarning/qCCritical
> 
> That's not doable in 100% of the cases, f.i. if one has to compile extra code to
> get the debug information that needs to be printed.

You can then use it like that:

If (qtCoreIo().isDebugEnabled()) {
    QString x = expensive();
    qCDebug(qtCoreIo) << "Expensive: " << x;
}

Anyhow, note that qCDebug(qtCoreIo) expands to

for (bool enabled = qtCoreIo().isDebugEnabled(); Q_UNLIKELY(enabled); enabled = false)
  QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, qtCoreIo().categoryName()).debug() <<

so this should be needed only if your 'expensive' operations aren't behind the << anyway.

> Also, what's the overhead of a qCDebug for a disabled category? Qt should
> never emit debug warnings in its default configuration, so we're talking about
> many hits to that.

The overhead for a non-enabled qCDebug is basically a function call + one boolean check (isDebugEnabled() will be inlined).

Regards

Kai

> 
> --
> Giuseppe D'Angelo


More information about the Development mailing list