From 2ea397f11d82ad0bb8bb5e4677cfefb1f2e4d1a2 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 11 Apr 2022 09:53:55 +0200 Subject: [PATCH] QmlProjectManager: Avoid use of RunControl::runConfiguration() The RunConfiguration might change and even die after the runcontrol starts. Change-Id: I628f3ae26c21fb41388b6104497ce5a6a6704c8a Reviewed-by: Tim Jenssen Reviewed-by: --- src/plugins/qmlpreview/qmlpreviewplugin.cpp | 5 ----- .../qmlprojectmanager/qmlmultilanguageaspect.cpp | 11 +++++++++++ .../qmlprojectmanager/qmlmultilanguageaspect.h | 7 +++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/plugins/qmlpreview/qmlpreviewplugin.cpp b/src/plugins/qmlpreview/qmlpreviewplugin.cpp index 2f76fd54f02..1cbecc042f1 100644 --- a/src/plugins/qmlpreview/qmlpreviewplugin.cpp +++ b/src/plugins/qmlpreview/qmlpreviewplugin.cpp @@ -449,11 +449,6 @@ void QmlPreviewPluginPrivate::setDirty() void QmlPreviewPluginPrivate::addPreview(ProjectExplorer::RunControl *preview) { m_runningPreviews.append(preview); - if (auto multiLanguageAspect = - preview->runConfiguration()->aspect()) { - connect(multiLanguageAspect, &QmlProjectManager::QmlMultiLanguageAspect::changed, - preview, &ProjectExplorer::RunControl::initiateStop); - } emit q->runningPreviewsChanged(m_runningPreviews); } diff --git a/src/plugins/qmlprojectmanager/qmlmultilanguageaspect.cpp b/src/plugins/qmlprojectmanager/qmlmultilanguageaspect.cpp index dc57689cad9..3a4d26f537d 100644 --- a/src/plugins/qmlprojectmanager/qmlmultilanguageaspect.cpp +++ b/src/plugins/qmlprojectmanager/qmlmultilanguageaspect.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -81,6 +82,16 @@ QmlMultiLanguageAspect::QmlMultiLanguageAspect(ProjectExplorer::Target *target) setDefaultValue(!databaseFilePath().isEmpty()); QVariantMap getDefaultValues; fromMap(getDefaultValues); + + addDataExtractor(this, &QmlMultiLanguageAspect::origin, &Data::origin); + + connect(this, &BoolAspect::changed, this, [this, target] { + for (ProjectExplorer::RunControl *runControl : + ProjectExplorer::ProjectExplorerPlugin::allRunControls()) { + if (runControl->aspect()->origin == this) + runControl->initiateStop(); + } + }); } QmlMultiLanguageAspect::~QmlMultiLanguageAspect() diff --git a/src/plugins/qmlprojectmanager/qmlmultilanguageaspect.h b/src/plugins/qmlprojectmanager/qmlmultilanguageaspect.h index 5eae6c78948..bc58b32b505 100644 --- a/src/plugins/qmlprojectmanager/qmlmultilanguageaspect.h +++ b/src/plugins/qmlprojectmanager/qmlmultilanguageaspect.h @@ -50,10 +50,17 @@ public: static QmlMultiLanguageAspect *current(ProjectExplorer::Project *project); static QmlMultiLanguageAspect *current(ProjectExplorer::Target *target); + struct Data : BaseAspect::Data + { + const void *origin = nullptr; + }; + signals: void currentLocaleChanged(const QString &locale); private: + const void *origin() const { return this; } + ProjectExplorer::Target *m_target = nullptr; mutable Utils::FilePath m_databaseFilePath; QString m_currentLocale;