QtSupport: Restrict QtVersionManagerImpl lifetime to plugin lifetime

This occasionally triggered crashes on static destruction when
hard-killing Qt Creator.

Giving QtVersionManagerImpl the plugin as QObject parent effectively
re-instates the lifetime behavior from before we moved to delayed
initialization. We keep the delayed initialization, at the (acceptable)
prize of a somewhat quirky setup.

Change-Id: I1b4be284a1b573325ed5cc441778eeb48b94c24b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2024-03-13 16:59:19 +01:00
parent 75b9b31c62
commit 5ebd4c833e
3 changed files with 16 additions and 3 deletions

View File

@@ -83,6 +83,8 @@ void QtSupportPlugin::initialize()
addTestCreator(createQtProjectImporterTest); addTestCreator(createQtProjectImporterTest);
#endif #endif
setupQtVersionManager(this);
setupDesktopQtVersion(); setupDesktopQtVersion();
setupEmbeddedLinuxQtVersion(); setupEmbeddedLinuxQtVersion();
setupGettingStartedWelcomePage(); setupGettingStartedWelcomePage();

View File

@@ -89,7 +89,8 @@ static PersistentSettingsWriter *m_writer = nullptr;
class QtVersionManagerImpl : public QObject class QtVersionManagerImpl : public QObject
{ {
public: public:
QtVersionManagerImpl() QtVersionManagerImpl(QObject *parent)
: QObject(parent)
{ {
qRegisterMetaType<FilePath>(); qRegisterMetaType<FilePath>();
@@ -135,10 +136,18 @@ public:
QTimer m_fileWatcherTimer; QTimer m_fileWatcherTimer;
}; };
static QObject *s_guard = nullptr;
void Internal::setupQtVersionManager(QObject *guard)
{
s_guard = guard;
}
QtVersionManagerImpl &qtVersionManagerImpl() QtVersionManagerImpl &qtVersionManagerImpl()
{ {
static QtVersionManagerImpl theQtVersionManager; QTC_CHECK(s_guard);
return theQtVersionManager; static auto theQtVersionManager = new QtVersionManagerImpl(s_guard);
return *theQtVersionManager;
} }
void QtVersionManagerImpl::triggerQtVersionRestore() void QtVersionManagerImpl::triggerQtVersionRestore()

View File

@@ -70,4 +70,6 @@ private:
static int getUniqueId(); static int getUniqueId();
}; };
namespace Internal { void setupQtVersionManager(QObject *guard); }
} // namespace QtSupport } // namespace QtSupport