diff --git a/src/plugins/welcome/welcomeplugin.cpp b/src/plugins/welcome/welcomeplugin.cpp index adc682267a9..c10c5ffab2a 100644 --- a/src/plugins/welcome/welcomeplugin.cpp +++ b/src/plugins/welcome/welcomeplugin.cpp @@ -160,7 +160,7 @@ private: void welcomePluginAdded(QObject*); void sceneGraphError(QQuickWindow::SceneGraphError, const QString &message); void facilitateQml(QQmlEngine *engine); - void addPages(const QList &pages); + void addPages(QQmlEngine *engine, const QList &pages); void addKeyboardShortcuts(); QWidget *m_modeWidget; @@ -296,13 +296,16 @@ void WelcomeMode::initPlugins() QSettings *settings = ICore::settings(); setActivePlugin(settings->value(QLatin1String(currentPageSettingsKeyC)).toInt()); - facilitateQml(m_welcomePage->engine()); + QQmlEngine *engine = m_welcomePage->engine(); + facilitateQml(engine); QList availablePages = PluginManager::getObjects(); - addPages(availablePages); + addPages(engine, availablePages); // make sure later added pages are made available too: - connect(PluginManager::instance(), &PluginManager::objectAdded, - this, &WelcomeMode::welcomePluginAdded); + connect(PluginManager::instance(), &PluginManager::objectAdded, engine, [this, engine](QObject *obj) { + if (IWelcomePage *page = qobject_cast(obj)) + addPages(engine, QList() << page); + }); QString path = resourcePath() + QLatin1String("/welcomescreen/welcomescreen.qml"); @@ -322,23 +325,14 @@ bool WelcomeMode::openDroppedFiles(const QList &urls) return false; } -void WelcomeMode::welcomePluginAdded(QObject *obj) -{ - IWelcomePage *page = qobject_cast(obj); - if (!page) - return; - addPages(QList() << page); -} - -void WelcomeMode::addPages(const QList &pages) +void WelcomeMode::addPages(QQmlEngine *engine, const QList &pages) { QList addedPages = pages; Utils::sort(addedPages, &IWelcomePage::priority); // insert into m_pluginList, keeping m_pluginList sorted by priority - QQmlEngine *engine = m_welcomePage->engine(); - auto addIt = addedPages.begin(); + auto addIt = addedPages.cbegin(); auto currentIt = m_pluginList.begin(); - while (addIt != addedPages.end()) { + while (addIt != addedPages.cend()) { IWelcomePage *page = *addIt; QTC_ASSERT(!m_idPageMap.contains(page->id()), ++addIt; continue); while (currentIt != m_pluginList.end() && (*currentIt)->priority() <= page->priority())