diff options
author | JiDe Zhang <zhangjide@uniontech.com> | 2021-01-16 04:27:39 +0800 |
---|---|---|
committer | Alexey Edelev <alexey.edelev@qt.io> | 2021-04-23 18:51:30 +0200 |
commit | 22e967c3049608f82abd32a0beb0b4b36ee134bf (patch) | |
tree | bb92fc22698ba34b596728214580e193e7068ecf /src/corelib/kernel/qcoreapplication.cpp | |
parent | f1c37ead59cff4ce5788c75a9183f327c0681480 (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
Pick-to: 6.1 6.0
Task-number: QTBUG-90341
Change-Id: I0ee70561dc57b857f8b3b1cf42c9dfe0cf45bd49
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src/corelib/kernel/qcoreapplication.cpp')
-rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 5ea01ec53d..5f25b1c025 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -251,6 +251,7 @@ Q_GLOBAL_STATIC(QStartUpFuncList, preRList) typedef QList<QtCleanUpFunction> QVFuncList; Q_GLOBAL_STATIC(QVFuncList, postRList) static QBasicMutex globalRoutinesMutex; +static bool preRoutinesCalled = false; /*! \internal @@ -264,8 +265,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. @@ -293,6 +296,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; @@ -854,6 +860,8 @@ void QCoreApplicationPrivate::init() */ QCoreApplication::~QCoreApplication() { + preRoutinesCalled = false; + qt_call_post_routines(); self = nullptr; |