diff --git a/src/libs/extensionsystem/pluginmanager.cpp b/src/libs/extensionsystem/pluginmanager.cpp index 1e0acd7093c..ae7cc386cc4 100644 --- a/src/libs/extensionsystem/pluginmanager.cpp +++ b/src/libs/extensionsystem/pluginmanager.cpp @@ -8,6 +8,7 @@ #include "optionsparser.h" #include "pluginmanager_p.h" #include "pluginspec.h" +#include "shutdownguard.h" #include @@ -235,6 +236,26 @@ using namespace Internal; static Internal::PluginManagerPrivate *d = nullptr; static PluginManager *m_instance = nullptr; +static QObject *m_shutdownGuard = nullptr; + +/*! + Returns an object that can be used as the parent for objects that should be + destroyed just at the end of the applications lifetime. + The object is destroyed after all plugins' aboutToShutdown methods + have finished, just before the plugins are deleted. + + Only use this from the application's main thread. + + \sa ExtensionSystem::IPlugin::aboutToShutdown() +*/ +QObject *shutdownGuard() +{ + if (!m_shutdownGuard) { + QTC_CHECK(Utils::isMainThread()); + m_shutdownGuard = new QObject; + } + return m_shutdownGuard; +} /*! Gets the unique plugin manager instance. @@ -1056,6 +1077,8 @@ void PluginManagerPrivate::deleteAll() Utils::futureSynchronizer()->isCancelOnWait(), Utils::futureSynchronizer()->cancelAllFutures()); Utils::futureSynchronizer()->waitForFinished(); // Synchronize all futures from all plugins + delete m_shutdownGuard; + m_shutdownGuard = nullptr; Utils::reverseForeach(loadQueue(), [this](PluginSpec *spec) { loadPlugin(spec, PluginSpec::Deleted); }); diff --git a/src/libs/extensionsystem/shutdownguard.h b/src/libs/extensionsystem/shutdownguard.h new file mode 100644 index 00000000000..b0a5ad4e08e --- /dev/null +++ b/src/libs/extensionsystem/shutdownguard.h @@ -0,0 +1,14 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#pragma once + +#include "extensionsystem_global.h" + +#include + +namespace ExtensionSystem { + +EXTENSIONSYSTEM_EXPORT QObject *shutdownGuard(); + +} // namespace ExtensionSystem