PyQt中的这两个clicked()信号有什么区别? [英] What is a difference between these two clicked() signals in PyQt?

查看:483
本文介绍了PyQt中的这两个clicked()信号有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

my_button.clicked.connect(my_func)

我通常使用第一个选项,但是后来我找到了第二个,并想知道它们之间有什么区别。 / p>

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

推荐答案

第一个选项是旧式信号和插槽语法,现在已过时。您仍然可以在PyQt4中使用它,但是PyQt5完全不支持它。第二个选项是新型信号和插槽语法,可以是在PyQt5和所有最新版本的PyQt4(在v4.5中引入)中使用。

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).

PyQt文档列出了旧式语法的以下缺点:

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



  • 它需要了解信号参数的C ++类型。

  • 它容易出错,因为如果您键入错误的信号名称或签名-则无论是连接信号还是发出信号
    ,都不会引发异常。

  • 它是冗长的。

  • 这不是Python语言。

  • 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.

这篇关于PyQt中的这两个clicked()信号有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆