handle messageboxes inside qt's thread

This commit is contained in:
Joakim L. Gilje
2021-11-29 12:25:27 +01:00
parent 97d844c3fc
commit 238fb7ef62
4 changed files with 12 additions and 11 deletions

View File

@@ -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. */

View File

@@ -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 <QDebug>
#include <QTimer>
#include <QKeyEvent>
#include <QMessageBox>
#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();
});

View File

@@ -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();

View File

@@ -2,7 +2,6 @@
#include <QDebug>
#include <QThread>
#include <QMessageBox>
#include <QStatusBar>
@@ -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<long>(header));
if (message <= (void*)7168) message = plat_get_string(reinterpret_cast<long>(message));
auto hdr = QString::fromWCharArray(reinterpret_cast<const wchar_t*>(header));
auto msg = QString::fromWCharArray(reinterpret_cast<const wchar_t*>(message));
QMessageBox box(QMessageBox::Warning, hdr, msg);
box.exec();
main_window->showMessage(hdr, msg);
return 0;
}