[Development] Let's get rid of qDebug/qWarning/qCritical!
Kurt Pattyn
kurt.pattyn at icloud.com
Thu Jan 9 07:58:04 CET 2014
On 08 Jan 2014, at 10:12, Koehne Kai <Kai.Koehne at digia.com> wrote:
>
> 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() <<
>
Out of curiosity: is there a reason you use 'for' and not an 'if' statement?
> 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).
>
If code size or performance is a problem for certain critical code sections, you could also use a full macro, like:
qCDebug(category, a << b << "some string");
This construct looks rather strange or even ugly, but has the advantage that it can be completely compiled away.
Regards,
Kurt
More information about the Development
mailing list