From 238fb7ef6222316c133904f032a49cb2ebdfb28b Mon Sep 17 00:00:00 2001 From: "Joakim L. Gilje" Date: Mon, 29 Nov 2021 12:25:27 +0100 Subject: [PATCH] handle messageboxes inside qt's thread --- src/qt/qt_main.cpp | 7 +++---- src/qt/qt_mainwindow.cpp | 8 ++++++-- src/qt/qt_mainwindow.hpp | 1 + src/qt/qt_ui.cpp | 7 ++----- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index 4d6062917..3fb6dd2ca 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -77,15 +77,14 @@ int main(int argc, char* argv[]) { QApplication app(argc, argv); elapsed_timer.start(); + main_window = new MainWindow(); + main_window->show(); + pc_init(argc, argv); if (! pc_init_modules()) { ui_msgbox_header(MBX_FATAL, VC(L"No ROMs found."), VC(L"86Box could not find any usable ROM images.\n\nPlease download a ROM set and extract it into the \"roms\" directory.")); return 6; } - - main_window = new MainWindow(); - main_window->show(); - pc_reset_hard_init(); /* Set the PAUSE mode depending on the renderer. */ diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 8c179bb2c..4f7b9fc9b 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -3,8 +3,6 @@ extern "C" { #include <86box/86box.h> -//#include <86box/keyboard.h> -//#include <86box/mouse.h> #include <86box/config.h> #include <86box/plat.h> @@ -15,6 +13,7 @@ extern "C" { #include #include #include +#include #include "qt_settings.hpp" @@ -26,6 +25,11 @@ 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::pollMouse, this, [] { sdl_mouse_poll(); }); diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 3428ca098..a22088830 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -25,6 +25,7 @@ signals: void setFullscreen(bool state); void setMouseCapture(bool state); + void showMessage(const QString& header, const QString& message); private slots: void on_actionFullscreen_triggered(); diff --git a/src/qt/qt_ui.cpp b/src/qt/qt_ui.cpp index 08614a48e..decca9f24 100644 --- a/src/qt/qt_ui.cpp +++ b/src/qt/qt_ui.cpp @@ -2,7 +2,6 @@ #include #include -#include #include @@ -57,16 +56,14 @@ void plat_mouse_capture(int on) { main_window->setMouseCapture(on > 0 ? true : false); } -int ui_msgbox_header(int flags, void *header, void* message) -{ +int ui_msgbox_header(int flags, void *header, void* message) { if (header <= (void*)7168) header = plat_get_string(reinterpret_cast(header)); if (message <= (void*)7168) message = plat_get_string(reinterpret_cast(message)); auto hdr = QString::fromWCharArray(reinterpret_cast(header)); auto msg = QString::fromWCharArray(reinterpret_cast(message)); - QMessageBox box(QMessageBox::Warning, hdr, msg); - box.exec(); + main_window->showMessage(hdr, msg); return 0; }