From 77a48d11a533c83f58880ecb2d1b7199c623b5f4 Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Fri, 20 Sep 2019 13:15:51 +0200 Subject: [PATCH] Fix crash on exit which was caused by trying to delete the QQmlApplicationEngine. I still unsure about the reason of the crash... --- ScreenPlay/app.cpp | 29 +++++++++++------------------ ScreenPlay/app.h | 13 ++++++------- ScreenPlay/main.cpp | 11 +++++++---- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/ScreenPlay/app.cpp b/ScreenPlay/app.cpp index eb04b804..1a149c90 100644 --- a/ScreenPlay/app.cpp +++ b/ScreenPlay/app.cpp @@ -13,7 +13,7 @@ App::App() qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); - qRegisterMetaType(); + qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); @@ -21,11 +21,9 @@ App::App() qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); -} -void App::init() -{ QGuiApplication::setWindowIcon(QIcon(":/assets/icons/favicon.ico")); + // Qt < 6.0 needs this init QtWebEngine QtWebEngine::initialize(); @@ -36,24 +34,19 @@ void App::init() m_profileListModel = make_shared(m_globalVariables); m_sdkConnector = make_shared(); m_settings = make_shared(m_globalVariables); + m_create = make_shared(m_globalVariables); + m_util = make_shared(new QNetworkAccessManager(this)); + m_screenPlayManager = make_shared(m_globalVariables, m_monitorListModel, m_sdkConnector); + QObject::connect(m_settings.get(), &Settings::resetInstalledListmodel, m_installedListModel.get(), &InstalledListModel::reset); - - m_create = std::make_shared(m_globalVariables); - - mainWindowEngine = std::make_unique(); - m_util = std::make_shared(mainWindowEngine->networkAccessManager()); - - m_screenPlayManager = std::make_shared(m_globalVariables, m_monitorListModel, m_sdkConnector); - - mainWindowEngine->load(QUrl(QStringLiteral("qrc:/main.qml"))); - // Instead of setting "renderType: Text.NativeRendering" every time // we can set it here once :) QQuickWindow::setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering); - // Set visible if the -silent parameter was not set - if (!QGuiApplication::instance()->arguments().contains("-silent")) { - m_settings->setMainWindowVisible(true); - } + + + m_installedListModel->init(); + } + diff --git a/ScreenPlay/app.h b/ScreenPlay/app.h index bced4baf..356183eb 100644 --- a/ScreenPlay/app.h +++ b/ScreenPlay/app.h @@ -24,7 +24,9 @@ #include "src/settings.h" #include "src/util.h" -using std::make_shared, +using std::make_unique, + std::unique_ptr, + std::make_shared, std::shared_ptr, ScreenPlay::Util, ScreenPlay::InstalledListModel, @@ -53,7 +55,6 @@ class App : public QObject { public: explicit App(); - void init(); static App* instance() { @@ -212,14 +213,12 @@ public slots: emit sdkConnectorChanged(m_sdkConnector.get()); } - private: - std::unique_ptr mainWindowEngine; + shared_ptr m_create; + shared_ptr m_screenPlayManager; + shared_ptr m_util; shared_ptr m_globalVariables; - shared_ptr m_screenPlayManager; - shared_ptr m_create; - shared_ptr m_util; shared_ptr m_settings; shared_ptr m_sdkConnector; diff --git a/ScreenPlay/main.cpp b/ScreenPlay/main.cpp index 6092093b..b8ecdc1e 100644 --- a/ScreenPlay/main.cpp +++ b/ScreenPlay/main.cpp @@ -4,9 +4,6 @@ int main(int argc, char* argv[]) { - // Needs to be created before - App* app = App::instance(); - QGuiApplication qtGuiApp(argc, argv); qmlRegisterSingletonType("ScreenPlay", 1, 0, "ScreenPlay", [](QQmlEngine* engine, QJSEngine*) -> QObject* { @@ -14,7 +11,13 @@ int main(int argc, char* argv[]) return App::instance(); }); - app->init(); + QQmlApplicationEngine m_mainWindowEngine; + m_mainWindowEngine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + // Set visible if the -silent parameter was not set + if (!QGuiApplication::instance()->arguments().contains("-silent")) { + App::instance()->settings()->setMainWindowVisible(true); + } return qtGuiApp.exec(); }