From 91341890ecb8a9f8fa65cf8ecb06b4b84be01235 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Thu, 11 May 2017 17:39:42 +0100 Subject: [PATCH] Use a blocking queued connection to CLogHandler::logLocalMessage when logging a fatal message from a worker thread. Hopefully this will allow assert messages to be recorded in the logs. --- src/blackmisc/loghandler.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/blackmisc/loghandler.cpp b/src/blackmisc/loghandler.cpp index 028588144..2ec027950 100644 --- a/src/blackmisc/loghandler.cpp +++ b/src/blackmisc/loghandler.cpp @@ -35,9 +35,17 @@ namespace BlackMisc } //! Qt message handler + //! \todo Qt 5.10: Use invokeMethod() overload taking pointer-to-member-function. void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message) { - CStatusMessage statusMessage(type, context, message); + const CStatusMessage statusMessage(type, context, message); + if (type == QtFatalMsg && CLogHandler::instance()->thread() != QThread::currentThread()) + { + // Fatal message means this thread is about to crash the application. A queued connection would be useless. + // Blocking queued connection means we pause this thread just long enough to let the main thread handle the message. + QMetaObject::invokeMethod(CLogHandler::instance(), "logLocalMessage", Qt::BlockingQueuedConnection, Q_ARG(BlackMisc::CStatusMessage, statusMessage)); + return; + } QMetaObject::invokeMethod(CLogHandler::instance(), "logLocalMessage", Q_ARG(BlackMisc::CStatusMessage, statusMessage)); }