Qt: Add function to recreate the main window

This commit is contained in:
Connor McLaughlin 2021-08-16 14:06:16 +10:00
parent 971af2cb5c
commit 47f85dc453
4 changed files with 19 additions and 3 deletions

View file

@ -84,7 +84,7 @@ int main(int argc, char* argv[])
if (!ParseCommandLineParameters(app, host_interface.get(), &boot_params))
return EXIT_FAILURE;
std::unique_ptr<MainWindow> window = std::make_unique<MainWindow>(host_interface.get());
MainWindow* window = new MainWindow(host_interface.get());
if (!host_interface->Initialize())
{
@ -112,7 +112,6 @@ int main(int argc, char* argv[])
int result = app.exec();
window.reset();
host_interface->Shutdown();
return result;
}

View file

@ -82,7 +82,8 @@ MainWindow::MainWindow(QtHostInterface* host_interface)
MainWindow::~MainWindow()
{
Assert(!m_display_widget);
m_host_interface->setMainWindow(nullptr);
if (m_host_interface->getMainWindow() == this)
m_host_interface->setMainWindow(nullptr);
Assert(!m_debugger_window);
}
@ -562,6 +563,19 @@ std::string MainWindow::getDeviceDiscPath(const QString& title)
return ret;
}
void MainWindow::recreate()
{
if (m_emulation_running)
m_host_interface->synchronousPowerOffSystem();
close();
m_host_interface->setMainWindow(nullptr);
MainWindow* new_main_window = new MainWindow(m_host_interface);
new_main_window->initializeAndShow();
deleteLater();
}
void MainWindow::onStartDiscActionTriggered()
{
std::string path(getDeviceDiscPath(tr("Start Disc")));

View file

@ -150,6 +150,7 @@ private:
void updateMenuSelectedTheme();
void ensureGameListLoaded();
std::string getDeviceDiscPath(const QString& title);
void recreate();
Ui::MainWindow m_ui;

View file

@ -99,6 +99,8 @@ bool QtHostInterface::Initialize()
void QtHostInterface::Shutdown()
{
stopThread();
delete m_main_window;
}
bool QtHostInterface::initializeOnThread()