summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiDe Zhang <zhangjide@uniontech.com>2021-01-16 04:27:39 +0800
committerAlexey Edelev <alexey.edelev@qt.io>2021-04-28 09:24:42 +0200
commit38564297e778f2197ceb1d829741192d44bb6082 (patch)
treed42b23fda48eb0ce32f64520a7f26c44df82f7c0 /src
parent73621cbf0a5f53990b2c7a966bc6fd71299ec8fe (diff)
fix: The QtStartUpFunction function may be called repeatedly
Don't call pre routine function in qAddPreRoutine if the qt_call_pre_routines is not called Task-number: QTBUG-90341 Change-Id: I0ee70561dc57b857f8b3b1cf42c9dfe0cf45bd49 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> (cherry picked from commit 22e967c3049608f82abd32a0beb0b4b36ee134bf)
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 67cc56449a..9c1f2afcb1 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -252,6 +252,7 @@ Q_GLOBAL_STATIC(QStartUpFuncList, preRList)
typedef QList<QtCleanUpFunction> QVFuncList;
Q_GLOBAL_STATIC(QVFuncList, postRList)
static QBasicMutex globalRoutinesMutex;
+static bool preRoutinesCalled = false;
/*!
\internal
@@ -265,8 +266,10 @@ void qAddPreRoutine(QtStartUpFunction p)
if (!list)
return;
- if (QCoreApplication::instance())
+ if (preRoutinesCalled) {
+ Q_ASSERT(QCoreApplication::instance());
p();
+ }
// Due to C++11 parallel dynamic initialization, this can be called
// from multiple threads.
@@ -294,6 +297,9 @@ void qRemovePostRoutine(QtCleanUpFunction p)
static void qt_call_pre_routines()
{
+ // After will be allowed invoke QtStartUpFunction when calling qAddPreRoutine
+ preRoutinesCalled = true;
+
if (!preRList.exists())
return;
@@ -855,6 +861,8 @@ void QCoreApplicationPrivate::init()
*/
QCoreApplication::~QCoreApplication()
{
+ preRoutinesCalled = false;
+
qt_call_post_routines();
self = nullptr;