MessageManager: Allow messages from non-UI threads

This relieves the caller of the burden of dispatching the call to the UI
thread.

Change-Id: Ic6455fb7f393d0e21c7e527c693ebf2441f0c028
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2020-01-30 12:45:10 +01:00
parent 03801e29ef
commit 8b117bcd86
3 changed files with 25 additions and 9 deletions

View File

@@ -31,6 +31,8 @@
#include <utils/qtcassert.h>
#include <QFont>
#include <QThread>
#include <QTimer>
using namespace Core;
@@ -91,7 +93,20 @@ void MessageManager::setWheelZoomEnabled(bool enabled)
m_messageOutputWindow->setWheelZoomEnabled(enabled);
}
void MessageManager::writeMessages(const QStringList &messages, PrintToOutputPaneFlags flags)
{
write(messages.join('\n'), flags);
}
void MessageManager::write(const QString &text, PrintToOutputPaneFlags flags)
{
if (QThread::currentThread() == instance()->thread())
doWrite(text, flags);
else
QTimer::singleShot(0, instance(), [text, flags] { doWrite(text, flags); });
}
void MessageManager::doWrite(const QString &text, PrintToOutputPaneFlags flags)
{
QTC_ASSERT(m_messageOutputWindow, return);