From 4dcba2ad259514fe21cda500120c05e0f7d1f094 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Tue, 27 Feb 2024 08:27:06 +0100 Subject: [PATCH] Core: Correct log view thread handling Fixes a crash when log messages are received from multiple threads. Fixes: QTCREATORBUG-30444 Change-Id: I51c78656da1dd30bcb51a801083d1714e474d8e5 Reviewed-by: Marcus Tillmanns --- src/plugins/coreplugin/loggingviewer.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/coreplugin/loggingviewer.cpp b/src/plugins/coreplugin/loggingviewer.cpp index 5e83c76df3e..d6aad897148 100644 --- a/src/plugins/coreplugin/loggingviewer.cpp +++ b/src/plugins/coreplugin/loggingviewer.cpp @@ -559,10 +559,16 @@ private: const QString timestamp = QDateTime::currentDateTime().toString("HH:mm:ss.zzz"); - if (rowCount() >= 1000000) // limit log to 1000000 items - destroyItem(itemForIndex(index(0, 0))); + auto append = [this, timestamp, type, category, msg] { + if (rowCount() >= 1000000) // limit log to 1000000 items + destroyItem(itemForIndex(index(0, 0))); + appendItem(LogEntry{timestamp, messageTypeToString(type), category, msg}); + }; - appendItem(LogEntry{timestamp, messageTypeToString(type), category, msg}); + if (QThread::currentThread() != thread()) + QMetaObject::invokeMethod(this, append, Qt::QueuedConnection); + else + append(); } private: