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

后端 未结 1 1012
栀梦
栀梦 2021-01-26 08:36
QtCore.QObject.connect(my_button, QtCore.SIGNAL(\'clicked()\'), my_func)

and

my_button.clicked.connect(my_func)

I usu

相关标签:
1条回答
  • 2021-01-26 09:18

    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.
    0 讨论(0)
提交回复
热议问题