Make sure QLoggingCategory default is available

This avoids crashes in case where qWarning() would be called from a
global static deleted after the one holding the default category. I
encountered this case with a QLockFile locked from a global static while
the application quits, it was calling qAppName which was triggering a
qWarning as the qapplication object was gone too.

Change-Id: I8910e8559d063e8f0a737bae3da5edc481ab84d3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
bb10
Kevin Ottens 2013-10-09 13:06:01 +02:00 committed by The Qt Project
parent 5466eb289f
commit c657bb7b51
1 changed files with 4 additions and 2 deletions

View File

@ -927,8 +927,10 @@ static void qt_message_print(QtMsgType msgType, const QMessageLogContext &contex
#ifndef QT_BOOTSTRAPPED
// qDebug, qWarning, ... macros do not check whether category is enabled
if (!context.category || (strcmp(context.category, "default") == 0)) {
if (!QLoggingCategory::defaultCategory().isEnabled(msgType))
return;
if (QLoggingCategory *defaultCategory = &QLoggingCategory::defaultCategory()) {
if (!defaultCategory->isEnabled(msgType))
return;
}
}
#endif