diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-06-17 12:36:21 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-06-20 19:05:54 +0000 |
commit | ef7cda00dd64acca3a5fa48ee3cb129c781506f2 (patch) | |
tree | 1a0312028f4a6020c730d72fb8345d315ebe6a36 /tests | |
parent | c38a40f7954f82d55d80f9689fdbafe9256528d4 (diff) |
Avoid misleading bindingStatus
Set it to nullptr on clear, and deal with possibly null bindingStatus.
Task-number: QTBUG-101177
Task-number: QTBUG-102403
Change-Id: I66cb4d505a4f7b377dc90b45ac13834fca19d399
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 0bd287627508c61a7abfd6430d8c1243ea153081)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index 92de7725e4..c0471890ee 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -79,6 +79,7 @@ private slots: void noFakeDependencies(); void threadSafety(); + void threadSafety2(); void bindablePropertyWithInitialization(); void noDoubleNotification(); @@ -1694,7 +1695,7 @@ void tst_QProperty::threadSafety() auto child1 = new ThreadSafetyTester(obj1); obj1->moveToThread(&workerThread); const auto mainThreadBindingStatus = QtPrivate::getBindingStatus({}); - QCOMPARE(qGetBindingStorage(child1)->status({}), mainThreadBindingStatus); + QCOMPARE(qGetBindingStorage(child1)->status({}), nullptr); workerThread.start(); bool correctStatus = false; @@ -1743,6 +1744,41 @@ void tst_QProperty::threadSafety() QCOMPARE(obj3->objectName(), "moved again"); } +class QPropertyUsingThread : public QThread +{ +public: + QPropertyUsingThread(QObject **dest, QThread *destThread) : dest(dest), destThread(destThread) {} + void run() override + { + scopedObj1.reset(new ThreadSafetyTester()); + scopedObj1->setObjectName("test"); + QObject *child = new ThreadSafetyTester(scopedObj1.get()); + child->setObjectName("child"); + exec(); + scopedObj1->moveToThread(destThread); + *dest = scopedObj1.release(); + } + std::unique_ptr<ThreadSafetyTester> scopedObj1; + QObject **dest; + QThread *destThread; +}; + +void tst_QProperty::threadSafety2() +{ + std::unique_ptr<QObject> movedObj; + { + QObject *tmp = nullptr; + QPropertyUsingThread workerThread(&tmp, QThread::currentThread()); + workerThread.start(); + workerThread.quit(); + workerThread.wait(); + movedObj.reset(tmp); + } + + QCOMPARE(movedObj->objectName(), "test"); + QCOMPARE(movedObj->children().first()->objectName(), "child"); +} + struct CustomType { CustomType() = default; |