forked from qt-creator/qt-creator
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:
@@ -31,6 +31,8 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
#include <QThread>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
|
||||||
@@ -91,7 +93,20 @@ void MessageManager::setWheelZoomEnabled(bool enabled)
|
|||||||
m_messageOutputWindow->setWheelZoomEnabled(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)
|
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);
|
QTC_ASSERT(m_messageOutputWindow, return);
|
||||||
|
|
||||||
|
|||||||
@@ -57,18 +57,21 @@ public:
|
|||||||
|
|
||||||
Q_DECLARE_FLAGS(PrintToOutputPaneFlags, PrintToOutputPaneFlag)
|
Q_DECLARE_FLAGS(PrintToOutputPaneFlags, PrintToOutputPaneFlag)
|
||||||
|
|
||||||
static void showOutputPane(Core::MessageManager::PrintToOutputPaneFlags flags = NoModeSwitch);
|
static void showOutputPane(PrintToOutputPaneFlags flags = NoModeSwitch);
|
||||||
|
|
||||||
static void setFont(const QFont &font);
|
static void setFont(const QFont &font);
|
||||||
static void setWheelZoomEnabled(bool enabled);
|
static void setWheelZoomEnabled(bool enabled);
|
||||||
|
|
||||||
public slots:
|
static void writeMessages(const QStringList &messages,
|
||||||
static void write(const QString &text,
|
PrintToOutputPaneFlags flags = NoModeSwitch);
|
||||||
Core::MessageManager::PrintToOutputPaneFlags flags = NoModeSwitch);
|
static void write(const QString &text, PrintToOutputPaneFlags flags = NoModeSwitch);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MessageManager();
|
MessageManager();
|
||||||
~MessageManager() override;
|
~MessageManager() override;
|
||||||
|
|
||||||
|
static void doWrite(const QString &text, PrintToOutputPaneFlags flags);
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
friend class Core::Internal::MainWindow;
|
friend class Core::Internal::MainWindow;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -94,11 +94,9 @@ static QByteArray runGcc(const FilePath &gcc, const QStringList &arguments, cons
|
|||||||
SynchronousProcessResponse response = cpp.runBlocking(cmdLine);
|
SynchronousProcessResponse response = cpp.runBlocking(cmdLine);
|
||||||
if (response.result != SynchronousProcessResponse::Finished ||
|
if (response.result != SynchronousProcessResponse::Finished ||
|
||||||
response.exitCode != 0) {
|
response.exitCode != 0) {
|
||||||
QTimer::singleShot(0, Core::MessageManager::instance(), [cmdLine, response] {
|
Core::MessageManager::writeMessages({"Compiler feature detection failure!",
|
||||||
Core::MessageManager::write("Compiler feature detection failure!");
|
response.exitMessage(cmdLine.toUserOutput(), 10),
|
||||||
Core::MessageManager::write(response.exitMessage(cmdLine.toUserOutput(), 10));
|
QString::fromUtf8(response.allRawOutput())});
|
||||||
Core::MessageManager::write(QString::fromUtf8(response.allRawOutput()));
|
|
||||||
});
|
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user