Python Pyqt Signals Slot

Posted on  by

It can be difficult for newcomers to configure signal and slot in PyQt5 who have no prior experience in Qt programming. Signal-Slot is one of the fundamental topics of Qt one should have a firm. The OP is asking about a perfectly legitimate need. Sometimes many menu items are auto-generated (or just very similar) and should refer to the same slot. There is a standard way to achieve this in PyQt which is recommended in the book and in tutorials. – Eli Bendersky Jun 2 '09 at 16:56. It's possible to send a python object of any type using PyQtPyObject in the signature. This is recommended when both signal and slot is implemented in python. By using PyQtPyObject we avoid unnecessary conversions between python objects and C types and it is more consistent with python dynamically typed nature.

I was to lazy to take a look at the new-style signal and slot support which was introduced in PyQt 4.5 until yesterday. I did know that there were something called new-style signals and slots but that was the end of the story. Now I have taken the time and I think it's a cleaner solution than the old-style.
I'll just give you a short intro to whet your appetite, find all details here yourself.
This is the old way of connecting a signal to a slot. To use the new-style support just replace line 11 with following code
The new-style support introduces an attribute with the same name as the signal, in this case clickedSlot.
If you need to define your own signal you'll do something like this (off the top of my head):
And the old way:Python pyqt signal slot
IMHO the

Python Qt Signals Slots

new-style

Python Pyqt Signals Slot Machine

support is more pythonic and you don't have to specify your signals as strings when connecting. If you use pydev (eclipse) you'll also have completion support for signals.