AlekseyN AlekseyN - 10 months ago 52
Python Question

What is a difference between these two clicked() signals in PyQt?

QtCore.QObject.connect(my_button, QtCore.SIGNAL('clicked()'), my_func)



I usually use the first option, but then I found the second one and want to know what is a difference between them.

Answer Source

The first option is the old-style signal and slot syntax, which is now obsolete. You can still use it in PyQt4, but it is not supported at all in PyQt5. The second option is the new-style signal and slot syntax, which can be used in PyQt5 and all recent versions of PyQt4 (it was introduced in v4.5).

The PyQt docs lists the following disadvantages of the old-style syntax:

  • It requires knowledge of the C++ types of signal arguments.
  • It is error prone in that if you mis-type the signal name or signature - then no exception is raised, either when the signal is connected or emitted.
  • It is verbose.
  • It is not Pythonic.