Qt: Fix Windows not being deleted

This commit is contained in:
Jeffrey Pfau 2015-06-18 19:57:01 -07:00
parent 5c3074ace9
commit 5e26f74f17
2 changed files with 9 additions and 1 deletions

View File

@ -42,6 +42,9 @@ GBAApp::GBAApp(int& argc, char* argv[])
QApplication::setApplicationVersion(projectVersion); QApplication::setApplicationVersion(projectVersion);
Window* w = new Window(&m_configController); Window* w = new Window(&m_configController);
connect(w, &Window::destroyed, [this]() {
m_windows[0] = nullptr;
});
m_windows[0] = w; m_windows[0] = w;
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
@ -79,7 +82,11 @@ Window* GBAApp::newWindow() {
return nullptr; return nullptr;
} }
Window* w = new Window(&m_configController, m_multiplayer.attached()); Window* w = new Window(&m_configController, m_multiplayer.attached());
m_windows[m_multiplayer.attached()] = w; int windowId = m_multiplayer.attached();
connect(w, &Window::destroyed, [this, windowId]() {
m_windows[windowId] = nullptr;
});
m_windows[windowId] = w;
w->setAttribute(Qt::WA_DeleteOnClose); w->setAttribute(Qt::WA_DeleteOnClose);
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
w->show(); w->show();

View File

@ -68,6 +68,7 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
{ {
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
setAcceptDrops(true); setAcceptDrops(true);
setAttribute(Qt::WA_DeleteOnClose);
m_controller = new GameController(this); m_controller = new GameController(this);
m_controller->setInputController(&m_inputController); m_controller->setInputController(&m_inputController);
m_controller->setOverrides(m_config->overrides()); m_controller->setOverrides(m_config->overrides());