diff --git a/src/corelib/tracing/qctf.cpp b/src/corelib/tracing/qctf.cpp index 1dafa582d9..00a196c926 100644 --- a/src/corelib/tracing/qctf.cpp +++ b/src/corelib/tracing/qctf.cpp @@ -15,6 +15,7 @@ QT_BEGIN_NAMESPACE static bool s_initialized = false; static bool s_triedLoading = false; static bool s_prevent_recursion = false; +static bool s_shutdown = false; static QCtfLib* s_plugin = nullptr; #if defined(Q_OS_ANDROID) @@ -59,18 +60,13 @@ static bool loadPlugin(bool &retry) s_plugin = qobject_cast(loader.instance()); if (!s_plugin) return false; - QObject *obj = loader.instance(); - if (obj) { - QObject::connect(obj, &QObject::destroyed, []() { - s_plugin = nullptr; - }); - } + s_plugin->shutdown(&s_shutdown); return true; } static bool initialize() { - if (s_prevent_recursion) + if (s_shutdown || s_prevent_recursion) return false; if (s_initialized || s_triedLoading) return s_initialized; diff --git a/src/corelib/tracing/qctf_p.h b/src/corelib/tracing/qctf_p.h index 0e39b74e9e..b8db869e09 100644 --- a/src/corelib/tracing/qctf_p.h +++ b/src/corelib/tracing/qctf_p.h @@ -232,6 +232,7 @@ public: virtual void doTracepoint(const QCtfTracePointEvent &point, const QByteArray &arr) = 0; virtual bool sessionEnabled() = 0; virtual QCtfTracePointPrivate *initializeTracepoint(const QCtfTracePointEvent &point) = 0; + virtual void shutdown(bool *shutdown) = 0; }; QT_END_NAMESPACE diff --git a/src/plugins/tracing/qctflib.cpp b/src/plugins/tracing/qctflib.cpp index c3fdeed660..bfbe6b2d87 100644 --- a/src/plugins/tracing/qctflib.cpp +++ b/src/plugins/tracing/qctflib.cpp @@ -50,6 +50,7 @@ void QCtfLibImpl::cleanup() { if (s_instance) delete s_instance; + s_instance = nullptr; } QCtfLibImpl::QCtfLibImpl() diff --git a/src/plugins/tracing/qctflib_p.h b/src/plugins/tracing/qctflib_p.h index 081dda1d04..d92730ec57 100644 --- a/src/plugins/tracing/qctflib_p.h +++ b/src/plugins/tracing/qctflib_p.h @@ -78,6 +78,10 @@ public: QCtfTracePointPrivate *initializeTracepoint(const QCtfTracePointEvent &point) override; void registerMetadata(const QCtfTraceMetadata &metadata); int eventId(); + void shutdown(bool *) override + { + + } static QCtfLib *instance(); static void cleanup(); diff --git a/src/plugins/tracing/qctfplugin.cpp b/src/plugins/tracing/qctfplugin.cpp index 8f2245bb28..daa2b3637e 100644 --- a/src/plugins/tracing/qctfplugin.cpp +++ b/src/plugins/tracing/qctfplugin.cpp @@ -22,9 +22,13 @@ public: ~QCtfTracePlugin() { m_cleanup = true; + *m_shutdown = true; QCtfLibImpl::cleanup(); } - + void shutdown(bool *shutdown) override + { + m_shutdown = shutdown; + } bool tracepointEnabled(const QCtfTracePointEvent &point) override { if (m_cleanup) @@ -51,6 +55,7 @@ public: } private: bool m_cleanup = false; + bool *m_shutdown = nullptr; }; #include "qctfplugin.moc"