From 21127b587b4c0ebf29dff94b308494e45e097941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 18 Nov 2022 16:39:37 +0100 Subject: [PATCH] QErrorMessage: Filter out categorized logging for QErrorMessage::qtHandler() The class was not written to handle categorized logging, which was added after its inception. Processing categorized logging can quickly lead to issues, as showing the QErrorMessage may trigger categorized logging in itself. Change-Id: Id1d3a75acc1e6d1a69493fa722a733ae2f1f5f63 Reviewed-by: Richard Moe Gustavsen --- src/widgets/dialogs/qerrormessage.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/widgets/dialogs/qerrormessage.cpp b/src/widgets/dialogs/qerrormessage.cpp index 0c5a6099d5..7d52d9207c 100644 --- a/src/widgets/dialogs/qerrormessage.cpp +++ b/src/widgets/dialogs/qerrormessage.cpp @@ -149,11 +149,16 @@ static QString msgType2i18nString(QtMsgType t) return QCoreApplication::translate("QErrorMessage", messages[t]); } -static void jump(QtMsgType t, const QMessageLogContext & /*context*/, const QString &m) +static void jump(QtMsgType t, const QMessageLogContext &context, const QString &m) { if (!qtMessageHandler) return; + auto *defaultCategory = QLoggingCategory::defaultCategory(); + if (context.category && defaultCategory + && qstrcmp(context.category, defaultCategory->categoryName()) != 0) + return; + QString rich = "

"_L1 + msgType2i18nString(t) + "

"_L1 + Qt::convertFromPlainText(m, Qt::WhiteSpaceNormal); @@ -254,6 +259,8 @@ void QErrorMessage::done(int a) Returns a pointer to a QErrorMessage object that outputs the default Qt messages. This function creates such an object, if there isn't one already. + + The object will only output log messages of QLoggingCategory::defaultCategory(). */ QErrorMessage * QErrorMessage::qtHandler()