diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index a20082b6304..f7b75d55021 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #if QT_CONFIG(regularexpression) #include @@ -138,6 +139,7 @@ namespace QTest { }; static IgnoreResultList *ignoreResultList = nullptr; + Q_CONSTINIT static QBasicMutex mutex; static std::vector failOnWarningList; @@ -151,6 +153,8 @@ namespace QTest { static bool handleIgnoredMessage(QtMsgType type, const QString &message) { + const QMutexLocker mutexLocker(&QTest::mutex); + if (!ignoreResultList) return false; IgnoreResultList *last = nullptr; @@ -270,6 +274,7 @@ void QTestLog::enterTestData(QTestData *data) int QTestLog::unhandledIgnoreMessages() { + const QMutexLocker mutexLocker(&QTest::mutex); int i = 0; QTest::IgnoreResultList *list = QTest::ignoreResultList; while (list) { @@ -290,6 +295,7 @@ void QTestLog::leaveTestFunction() void QTestLog::printUnhandledIgnoreMessages() { + const QMutexLocker mutexLocker(&QTest::mutex); QString message; QTest::IgnoreResultList *list = QTest::ignoreResultList; while (list) { @@ -310,6 +316,7 @@ void QTestLog::printUnhandledIgnoreMessages() void QTestLog::clearIgnoreMessages() { + const QMutexLocker mutexLocker(&QTest::mutex); QTest::IgnoreResultList::clearList(QTest::ignoreResultList); } @@ -594,6 +601,7 @@ void QTestLog::ignoreMessage(QtMsgType type, const char *msg) { QTEST_ASSERT(msg); + const QMutexLocker mutexLocker(&QTest::mutex); QTest::IgnoreResultList::append(QTest::ignoreResultList, type, QString::fromUtf8(msg)); } @@ -602,6 +610,7 @@ void QTestLog::ignoreMessage(QtMsgType type, const QRegularExpression &expressio { QTEST_ASSERT(expression.isValid()); + const QMutexLocker mutexLocker(&QTest::mutex); QTest::IgnoreResultList::append(QTest::ignoreResultList, type, QVariant(expression)); } #endif // QT_CONFIG(regularexpression)