Qt Signal Slot Base Class
There are some concepts to be clarified
So the GUI class defines slots and signals, the signals are emitted in the implemented interface functions. The signals and slots are connected using: @'connect(this, SIGNAL(xyz), this SLOT(xyz));'@ I think the problem is that the intface functions that emit the signals are running in thread a but the GUI runs in thread b. Qt's signals and slots mechanism does not require classes to have knowledge of each other, which makes it much easier to develop highly reusable classes. Since signals and slots are type-safe, type errors are reported as warnings and do not cause crashes to occur. For example, if a Quit button's clicked signal is connected to the application's quit slot, a user's click on Quit makes the application terminate. In code, this is written as connect(button, SIGNAL (clicked), qApp, SLOT.
[QT signal & slot] VS [Python signal & slot]
All the predefined signals & slots provided by pyqt are implemented by QT's c++ code. Whenever you want to have a customized signal & slot in Python, it is a python signal & slot. Hence there are four cases to emits a signal to a slot:
Qt Signal Slot Example
- from a QT signal to a QT slot
- from a QT signal to a Python slot
- from a Python signal to a QT slot
- from a Python signal to a Python slot
The code below shows how to connect for these four different scnarios
Qt Signal And Slots
Conclusion is --
Signal signature for Python signal differentiate from that of QT signal in that it doesn't have the parenthesis and can be passed any python data types when you emit it. The Python signal is created when you emit it.
Qt Signal Slot Parameter
For slot, there are three forms of signatures.
- s.connect(w, SIGNAL('signalSignature'), functionName)
- s.connect(w,SIGNAL('signalSignature'), instance.methodName)
- s.connect(w,SIGNAL('signalSignature'), instance, SLOT('slotSignature'))
Number 1 & 2 are available for Python slot, while number 2 & 3 are available for QT slot. It is clear that besides QT predefined slot, any python callable function/methods is qulified to be a Python slot.
These points are made in Summerfield's article on Signals and Slots.
How Qt Signal And Slots Works
[Old style qt signal & slot] VS [new style qt singal & slot]
Qt Signal Slot Base Classic
Well, all the description above is based on the old style pyqt signal & slot. As @Idan K suggested there is an alternative new-style to do the things, especially for the Python signal. Refer to here for more.