fixup showMessage from both qt thread and external thread, while blocking
This commit is contained in:
@@ -12,6 +12,7 @@ extern "C" {
|
||||
#include <QWindow>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
#include <QThread>
|
||||
#include <QKeyEvent>
|
||||
#include <QMessageBox>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user