[PyQt] converting old signal/slot to new signal/slot

Baz Walter bazwal at ftml.net
Wed May 27 19:06:35 BST 2015


On 27/05/15 16:43, c c wrote:
> I've also looked at the Qt documentation for QtAssistant and I cant
> see a change between Qt4 and Qt5 Qobject connect() method so I'm at a
> loss as to why we have the new signal/slot system in PyQt5 (I am
> aware that it was introduced in Qt4. I'm sure as I get to grips with
> pyQt / pyQt5 the reson will become apparent but I'm a long way off of
> that) Hopefully someone can provide guidance and show me the light.

As you say, the new-style signal and slot syntax was introduced in 
PyQt4. I think that would have been with version 4.5, though, and so the 
old-style syntax had to be maintained alongside it for the purposes of 
backwards compatibility. The new-style syntax has been around for almost 
six years, now - so it's hardly "new" any more.

Why introduce the new-style syntax? Well, the old-style syntax is 
verbose, difficult to get right (especially if you don't know C++), and 
does not raise errors if you get it wrong. The new-style syntax is 
simply much more pythonic, and, now that PyQt5 can break compatibility 
with PyQt4, there is no need to maintain support for the old-style 
syntax - and so it has gone. In most other respects, though, PyQt5 is 
still very similar to PyQt4, and so porting is not usually a significant 
burden.

For more details, I suggest you go to the PyQt5 docs and read through 
the "Support for Signals and Slots" section:

     http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html

and the "Differences Between PyQt4 and PyQt5" section:

     http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html

If you want up-to-date example code, download the PyQt source from here:

     http://www.riverbankcomputing.com/software/pyqt/download5

and consult the README file in the examples directory.

-- 
Regards
Baz Walter


More information about the PyQt mailing list