From eec4ed3c1e5a033b10594bf64f6d0c1bad23705f Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 7 Feb 2017 15:42:39 -0800 Subject: [PATCH] Qt: Fix linking after some windows have been closed --- CHANGES | 1 + src/platform/qt/GBAApp.cpp | 47 +++++++++++++++++++------------------- src/platform/qt/GBAApp.h | 6 ++--- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CHANGES b/CHANGES index 7299cbdd2..4150b5468 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,7 @@ Bugfixes: - Tools: Fix recurring multiple times over the same library - GBA I/O: Handle audio registers specially when deserializing - Util: Fix highest-fd socket not being returned by SocketAccept + - Qt: Fix linking after some windows have been closed Misc: - Qt: Improved HiDPI support - Feature: Support ImageMagick 7 diff --git a/src/platform/qt/GBAApp.cpp b/src/platform/qt/GBAApp.cpp index 7b41f8d0f..2a4849c49 100644 --- a/src/platform/qt/GBAApp.cpp +++ b/src/platform/qt/GBAApp.cpp @@ -31,7 +31,6 @@ mLOG_DEFINE_CATEGORY(QT, "Qt"); GBAApp::GBAApp(int& argc, char* argv[]) : QApplication(argc, argv) - , m_windows{} , m_db(nullptr) { g_app = this; @@ -78,10 +77,10 @@ GBAApp::GBAApp(int& argc, char* argv[]) AudioProcessor::setDriver(static_cast(m_configController.getQtOption("audioDriver").toInt())); } Window* w = new Window(&m_configController); - connect(w, &Window::destroyed, [this]() { - m_windows[0] = nullptr; + connect(w, &Window::destroyed, [this, w]() { + m_windows.removeAll(w); }); - m_windows[0] = w; + m_windows.append(w); if (loaded) { w->argumentsPassed(&args); @@ -112,15 +111,15 @@ bool GBAApp::event(QEvent* event) { } Window* GBAApp::newWindow() { - if (m_multiplayer.attached() >= MAX_GBAS) { + if (m_windows.count() >= MAX_GBAS) { return nullptr; } Window* w = new Window(&m_configController, m_multiplayer.attached()); int windowId = m_multiplayer.attached(); - connect(w, &Window::destroyed, [this, windowId]() { - m_windows[windowId] = nullptr; + connect(w, &Window::destroyed, [this, w]() { + m_windows.removeAll(w); }); - m_windows[windowId] = w; + m_windows.append(w); w->setAttribute(Qt::WA_DeleteOnClose); w->loadConfig(); w->show(); @@ -133,27 +132,27 @@ GBAApp* GBAApp::app() { return g_app; } -void GBAApp::pauseAll(QList* paused) { - for (int i = 0; i < MAX_GBAS; ++i) { - if (!m_windows[i] || !m_windows[i]->controller()->isLoaded() || m_windows[i]->controller()->isPaused()) { +void GBAApp::pauseAll(QList* paused) { + for (auto& window : m_windows) { + if (!window->controller()->isLoaded() || window->controller()->isPaused()) { continue; } - m_windows[i]->controller()->setPaused(true); - paused->append(i); + window->controller()->setPaused(true); + paused->append(window); } } -void GBAApp::continueAll(const QList* paused) { - for (int i : *paused) { - m_windows[i]->controller()->setPaused(false); +void GBAApp::continueAll(const QList& paused) { + for (auto& window : paused) { + window->controller()->setPaused(false); } } QString GBAApp::getOpenFileName(QWidget* owner, const QString& title, const QString& filter) { - QList paused; + QList paused; pauseAll(&paused); QString filename = QFileDialog::getOpenFileName(owner, title, m_configController.getQtOption("lastDirectory").toString(), filter); - continueAll(&paused); + continueAll(paused); if (!filename.isEmpty()) { m_configController.setQtOption("lastDirectory", QFileInfo(filename).dir().path()); } @@ -161,10 +160,10 @@ QString GBAApp::getOpenFileName(QWidget* owner, const QString& title, const QStr } QString GBAApp::getSaveFileName(QWidget* owner, const QString& title, const QString& filter) { - QList paused; + QList paused; pauseAll(&paused); QString filename = QFileDialog::getSaveFileName(owner, title, m_configController.getQtOption("lastDirectory").toString(), filter); - continueAll(&paused); + continueAll(paused); if (!filename.isEmpty()) { m_configController.setQtOption("lastDirectory", QFileInfo(filename).dir().path()); } @@ -172,10 +171,10 @@ QString GBAApp::getSaveFileName(QWidget* owner, const QString& title, const QStr } QString GBAApp::getOpenDirectoryName(QWidget* owner, const QString& title) { - QList paused; + QList paused; pauseAll(&paused); QString filename = QFileDialog::getExistingDirectory(owner, title, m_configController.getQtOption("lastDirectory").toString()); - continueAll(&paused); + continueAll(paused); if (!filename.isEmpty()) { m_configController.setQtOption("lastDirectory", QFileInfo(filename).dir().path()); } @@ -230,13 +229,13 @@ GBAApp::FileDialog::FileDialog(GBAApp* app, QWidget* parent, const QString& capt } int GBAApp::FileDialog::exec() { - QList paused; + QList paused; m_app->pauseAll(&paused); bool didAccept = QFileDialog::exec() == QDialog::Accepted; QStringList filenames = selectedFiles(); if (!filenames.isEmpty()) { m_app->m_configController.setQtOption("lastDirectory", QFileInfo(filenames[0]).dir().path()); } - m_app->continueAll(&paused); + m_app->continueAll(paused); return didAccept; } diff --git a/src/platform/qt/GBAApp.h b/src/platform/qt/GBAApp.h index d54712744..e01b2a159 100644 --- a/src/platform/qt/GBAApp.h +++ b/src/platform/qt/GBAApp.h @@ -62,11 +62,11 @@ private: Window* newWindowInternal(); - void pauseAll(QList* paused); - void continueAll(const QList* paused); + void pauseAll(QList* paused); + void continueAll(const QList& paused); ConfigController m_configController; - Window* m_windows[MAX_GBAS]; + QList m_windows; MultiplayerController m_multiplayer; NoIntroDB* m_db; };