diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 48c75973f7f..0aa120ee1be 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -489,6 +489,11 @@ QCoreApplicationPrivate::~QCoreApplicationPrivate() QCoreApplicationPrivate::clearApplicationFilePath(); } +bool QCoreApplicationPrivate::isAlive() noexcept +{ + return qApp != nullptr; +} + #ifndef QT_NO_QOBJECT void QCoreApplicationPrivate::cleanupThreadData() diff --git a/src/corelib/kernel/qcoreapplication_p.h b/src/corelib/kernel/qcoreapplication_p.h index 0a51a0b5de8..ad99e2d5e0e 100644 --- a/src/corelib/kernel/qcoreapplication_p.h +++ b/src/corelib/kernel/qcoreapplication_p.h @@ -64,6 +64,7 @@ public: #endif ~QCoreApplicationPrivate(); + static bool isAlive() noexcept; void init(); QString appName() const; diff --git a/src/corelib/thread/qthreadstorage.cpp b/src/corelib/thread/qthreadstorage.cpp index c2029fe1b3c..3b2d4f5c9ca 100644 --- a/src/corelib/thread/qthreadstorage.cpp +++ b/src/corelib/thread/qthreadstorage.cpp @@ -3,6 +3,7 @@ #include "qthreadstorage.h" +#include "private/qcoreapplication_p.h" #include "qthread.h" #include "qthread_p.h" #include "qmutex.h" @@ -156,9 +157,9 @@ void QThreadStorageData::finish(void **p) locker.unlock(); if (!destructor) { - if (QThread::currentThread()) - qWarning("QThreadStorage: Thread %p exited after QThreadStorage %d destroyed", - QThread::currentThread(), i); + if (QCoreApplicationPrivate::isAlive()) + qWarning("QThreadStorage: entry %d destroyed before end of thread %p", + i, QThread::currentThread()); continue; } destructor(q); //crash here might mean the thread exited after qthreadstorage was destroyed