aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests
diff options
context:
space:
mode:
authorAdrian Herrmann <adrian.herrmann@qt.io>2023-11-16 20:37:13 +0100
committerAdrian Herrmann <adrian.herrmann@qt.io>2023-11-24 17:32:48 +0100
commit671c182dce91c387037894017be314564e054c00 (patch)
tree5d8061c027acb70c6fc904ada56176acad3e7628 /sources/pyside6/tests
parent3a058afcd7ae497c085ea0b0891d164caa38f1fe (diff)
QTimer: Implement singleShot signatures w/ context
On C++, it is possible to call singleShot timers with a context object as an argument. This allows posting events to the event loop of the given context object's thread, instead of the thread of the current thread. Implement corresponding signatures to add this capability to Qt for Python. Pick-to: 6.6 Change-Id: I0c4e3ef4b859cdfaac07415ff64c440821e7f442 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6/tests')
-rw-r--r--sources/pyside6/tests/QtCore/qtimer_singleshot_test.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/sources/pyside6/tests/QtCore/qtimer_singleshot_test.py b/sources/pyside6/tests/QtCore/qtimer_singleshot_test.py
index 770c9c1a9..1392281fa 100644
--- a/sources/pyside6/tests/QtCore/qtimer_singleshot_test.py
+++ b/sources/pyside6/tests/QtCore/qtimer_singleshot_test.py
@@ -14,7 +14,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QObject, QTimer, QCoreApplication, Signal
+from PySide6.QtCore import QObject, QThread, QTimer, Signal
from helper.usesqapplication import UsesQApplication
@@ -32,6 +32,19 @@ class WatchDog(QObject):
self.watched.exit_app_cb()
+class ThreadForContext(QThread):
+ def __init__(self):
+ super().__init__()
+ self.called = False
+ self.qthread = None
+ self.context = QObject()
+
+ def run(self):
+ self.called = True
+ self.qthread = QThread.currentThread()
+ self.exec()
+
+
class TestSingleShot(UsesQApplication):
'''Test case for QTimer.singleShot'''
@@ -40,6 +53,7 @@ class TestSingleShot(UsesQApplication):
UsesQApplication.setUp(self)
self.watchdog = WatchDog(self)
self.called = False
+ self.qthread = None
def tearDown(self):
# Release resources
@@ -51,6 +65,8 @@ class TestSingleShot(UsesQApplication):
def callback(self):
self.called = True
+ self.qthread = QThread.currentThread()
+ self.qthread.exit()
self.app.quit()
def testSingleShot(self):
@@ -58,6 +74,17 @@ class TestSingleShot(UsesQApplication):
self.app.exec()
self.assertTrue(self.called)
+ def testSingleShotWithContext(self):
+ thread = ThreadForContext()
+ thread.start()
+ thread.context.moveToThread(thread)
+ QTimer.singleShot(100, thread.context, self.callback)
+ self.app.exec()
+ thread.wait()
+ self.assertTrue(self.called)
+ self.assertTrue(thread.called)
+ self.assertEqual(self.qthread, thread.qthread)
+
class SigEmitter(QObject):
@@ -93,4 +120,3 @@ class TestSingleShotSignal(UsesQApplication):
if __name__ == '__main__':
unittest.main()
-