Signal Slot Qthread

Cross-thread signal-slot connections are implemented by dispatching a QMetaCallEvent to the target object. A QObject instance can be moved to a thread, where it will process its events, such as timer events or slot/method calls. To do work on a thread, first create your own worker class that derives from QObject. Then move it to the thread. For signals, the thread affinity doesn’t matter. But for slots it matters a lot. Subclassing QThread. Now you can perhaps appreciate why subclassing QThread can be a problem. If you have anything using slots in the subclass objects, the thread affinity will mean that it will use the original thread. Signals & Slots Signals and slots are used for communication between objects. The signals and slots mechanism is a central feature of Qt and probably the part that differs most from the features provided by other frameworks. Signals and slots are made possible by Qt's meta-object system. This is an example of threading using QThread and signal/slots of Qt libraries in Python using PySide. The same concepts should also be valid for PyQt bindings.

Graphical applications (GUI) are event-driven, unlike console or terminal applications. A users action like clicks a button or selecting an item in a list is called an event.

If an event takes place, each PyQt5 widget can emit a signal. A signal does not execute any action, that is done by a slot.

Qt Signal Slot Qthread

Related course:
Create GUI Apps with PyQt5

Qthread Signal Slot Example

Signals and slot introduction
Consider this example:

The button click (signal) is connected to the action (slot). In this example, the method slot_method will be called if the signal emits.

This principle of connecting slots methods or function to a widget, applies to all widgets,

or we can explicitly define the signal:

PyQt supports many type of signals, not just clicks.

Example
We can create a method (slot) that is connected to a widget. A slot is any callable function or method.

On running the application, we can click the button to execute the action (slot).

Qthreadpool Signal Slot

Signal Slot Qthread

Qthread Signal Slot

If you are new to programming Python PyQt, I highly recommend this book.