summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qtimer
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-03-21 21:38:11 -1000
committerThiago Macieira <thiago.macieira@intel.com>2023-03-23 13:22:23 -1000
commit4d90c4e74a6aa34d5aabfb91ec304da1f02df3e3 (patch)
treef0b0e786e7157d5677b10f909da7074a1f173696 /tests/auto/corelib/kernel/qtimer
parentf7167ae82fd74d69f2b138fb60a36ed7f863b380 (diff)
QTimer: fix new-style slot invocation for receiver in another thread
For single-shot timers, at least. QSingleShotTimer had either an optimization or the only way to make new-style slot invocations by storing the QSlotObject pointer and calling it directly. Instead of doing that, let's just actually connect and let QObject handle the actual delivery. [ChangeLog][QtCore][QTimer] Fixed a bug that caused slots connected to single-slot timers using the new-style connection mechanism to be delivered in the wrong thread. Fixes: QTBUG-112162 Pick-to: 5.15 6.2 6.5 Change-Id: Idd5e1bb52be047d7b4fffffd174eadb227ab65ee Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Diffstat (limited to 'tests/auto/corelib/kernel/qtimer')
-rw-r--r--tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
index e2bde37a7e..5c39fc5d91 100644
--- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
+++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
@@ -1006,18 +1006,21 @@ void tst_QTimer::postedEventsShouldNotStarveTimers()
}
struct DummyFunctor {
- void operator()() {}
+ static QThread *callThread;
+ void operator()() { callThread = QThread::currentThread(); }
};
+QThread *DummyFunctor::callThread = nullptr;
void tst_QTimer::crossThreadSingleShotToFunctor()
{
- // We're testing for crashes here, so the test simply running to
- // completion is considered a success
+ // We're also testing for crashes here, so the test simply running to
+ // completion is part of the success
QThread t;
t.start();
QObject* o = new QObject();
o->moveToThread(&t);
+ DummyFunctor::callThread = nullptr;
for (int i = 0; i < 10000; i++) {
QTimer::singleShot(0, o, DummyFunctor());
@@ -1026,6 +1029,8 @@ void tst_QTimer::crossThreadSingleShotToFunctor()
t.quit();
t.wait();
delete o;
+
+ QCOMPARE(DummyFunctor::callThread, &t);
}
void tst_QTimer::callOnTimeout()