diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 4f7b9fc9b..34f3a0340 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -12,6 +12,7 @@ extern "C" { #include #include #include +#include #include #include @@ -25,10 +26,7 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); - connect(this, &MainWindow::showMessage, this, [this](const QString& header, const QString& message) { - QMessageBox box(QMessageBox::Warning, header, message, QMessageBox::NoButton, this); - box.exec(); - }, Qt::BlockingQueuedConnection); + connect(this, &MainWindow::showMessageForNonQtThread, this, &MainWindow::showMessage_, Qt::BlockingQueuedConnection); connect(this, &MainWindow::pollMouse, this, [] { sdl_mouse_poll(); @@ -288,3 +286,16 @@ static const uint16_t xfree86_keycode_table[keycode_entries] = { void MainWindow::on_actionFullscreen_triggered() { setFullscreen(true); } + +void MainWindow::showMessage(const QString& header, const QString& message) { + if (QThread::currentThread() == this->thread()) { + showMessage_(header, message); + } else { + emit showMessageForNonQtThread(header, message); + } +} + +void MainWindow::showMessage_(const QString &header, const QString &message) { + QMessageBox box(QMessageBox::Warning, header, message, QMessageBox::NoButton, this); + box.exec(); +} diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index a22088830..655a8edc8 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -15,6 +15,8 @@ class MainWindow : public QMainWindow public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); + + void showMessage(const QString& header, const QString& message); signals: void paint(const QImage& image); void resizeContents(int w, int h); @@ -25,8 +27,8 @@ signals: void setFullscreen(bool state); void setMouseCapture(bool state); - void showMessage(const QString& header, const QString& message); + void showMessageForNonQtThread(const QString& header, const QString& message); private slots: void on_actionFullscreen_triggered(); void on_actionSettings_triggered();