From de4795f1a9ab597c52fb3a531e5580fe6d12f3e6 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 27 Jun 2025 09:47:24 +0200 Subject: Add section about Thread affinity to signals_and_slots.rst Pick-to: 6.9 Task-number: PYSIDE-3124 Change-Id: Ib795aca1a2ed75b31821a90c11ccb2bdfd08f9fc Reviewed-by: Ece Cinucen Reviewed-by: Shyamnath Premnadh --- .../doc/tutorials/basictutorial/signals_and_slots.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'sources/pyside6/doc/tutorials/basictutorial') diff --git a/sources/pyside6/doc/tutorials/basictutorial/signals_and_slots.rst b/sources/pyside6/doc/tutorials/basictutorial/signals_and_slots.rst index 1b0d1c809..c1f56df26 100644 --- a/sources/pyside6/doc/tutorials/basictutorial/signals_and_slots.rst +++ b/sources/pyside6/doc/tutorials/basictutorial/signals_and_slots.rst @@ -187,6 +187,25 @@ environment variable: export QT_LOGGING_RULES="qt.pyside.libpyside.warning=true" +Thread affinity ++++++++++++++++ + +In a multi-threaded application, signals can be emitted from senders belonging +to a different thread than the receiver. For non-Slot type receivers, the code +is then executed in the sender's thread context. + +However, for methods of :class:`~PySide6.QtCore.QObject` derived classes +decorated with @Slot, this is usually different since they are associated with +threads (see :meth:`~PySide6.QtCore.QObject.moveToThread`). This depends on +last parameter of the :meth:`~PySide6.QtCore.QObject.connect` method which is +of type :class:`PySide6.QtCore.Qt.ConnectionType`. + +When ``Qt.ConnectionType.AutoConnection`` (default) or +``Qt.ConnectionType.QueuedConnection`` are passed, the receiver code will be +executed in the thread context of the receiver object. This is useful for +passing results from background threads into GUI classes, which need to use the +main thread. + .. _overloading-signals-and-slots: Overloading Signals and Slots with Different Types -- cgit v1.2.3