From 70f47b01d375ab1d3687b2d448c601fdc15fab20 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 20 Jun 2018 14:56:53 +0200 Subject: [PATCH] fix(App): do not create windows later to avoid warning and abort (QQmlComponent: Cannot create new component instance before completing the previous) --- src/app/App.cpp | 40 +++++++++++++++++++--------------------- src/app/App.hpp | 4 ++-- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/app/App.cpp b/src/app/App.cpp index 36b68590..12661dd4 100644 --- src/app/App.cpp.orig +++ src/app/App.cpp @@ -147,8 +147,6 @@ qInfo() << QStringLiteral("Restarting app..."); delete mEngine; - mCallsWindow = nullptr; - mSettingsWindow = nullptr; CoreManager::uninit(); @@ -232,10 +230,7 @@ // ----------------------------------------------------------------------------- -QQuickWindow *App::getCallsWindow () { - if (!mCallsWindow) - mCallsWindow = ::createSubWindow(mEngine, QML_VIEW_CALLS_WINDOW); - +QQuickWindow *App::getCallsWindow () const { return mCallsWindow; } @@ -245,18 +240,7 @@ ); } -QQuickWindow *App::getSettingsWindow () { - if (!mSettingsWindow) { - mSettingsWindow = ::createSubWindow(mEngine, QML_VIEW_SETTINGS_WINDOW); - QObject::connect(mSettingsWindow, &QWindow::visibilityChanged, this, [](QWindow::Visibility visibility) { - if (visibility == QWindow::Hidden) { - qInfo() << QStringLiteral("Update nat policy."); - shared_ptr core = CoreManager::getInstance()->getCore(); - core->setNatPolicy(core->getNatPolicy()); - } - }); - } - +QQuickWindow *App::getSettingsWindow () const { return mSettingsWindow; } @@ -504,6 +488,17 @@ void App::openAppAfterInit () { qInfo() << QStringLiteral("Open linphone app."); + + // Create other windows. + mCallsWindow = createSubWindow(mEngine, QML_VIEW_CALLS_WINDOW); + mSettingsWindow = createSubWindow(mEngine, QML_VIEW_SETTINGS_WINDOW); + QObject::connect(mSettingsWindow, &QWindow::visibilityChanged, this, [](QWindow::Visibility visibility) { + if (visibility == QWindow::Hidden) { + qInfo() << QStringLiteral("Update nat policy."); + shared_ptr core = CoreManager::getInstance()->getCore(); + core->setNatPolicy(core->getNatPolicy()); + } + }); QQuickWindow *mainWindow = getMainWindow(); diff --git a/src/app/App.hpp b/src/app/App.hpp index cdae4a06..21ad9617 100644 --- src/app/App.hpp.orig +++ src/app/App.hpp @@ -79,8 +79,8 @@ exit(APP_CODE_RESTART); } - Q_INVOKABLE QQuickWindow *getCallsWindow (); - Q_INVOKABLE QQuickWindow *getSettingsWindow (); + Q_INVOKABLE QQuickWindow *getCallsWindow () const; + Q_INVOKABLE QQuickWindow *getSettingsWindow () const; Q_INVOKABLE static void smartShowWindow (QQuickWindow *window);