PyQt5 在哪个模块中找到了emit 方法? [英] PyQt5 in what module is the emit method found?
问题描述
有人为我运行此代码作为健全性检查会很有帮助.
Python 3.3.1(默认,2013 年 4 月 17 日,22:30:32)[GCC 4.7.3] 在 Linux 上输入帮助"、版权"、信用"或许可"以获取更多信息.>>>从 PyQt5.QtCore 导入 pyqtSignal>>>for i in dir(pyqtSignal):...如果我 == 'emit':...打印(真)...>>>
是否为其他人返回 true?请注意,从 PyQt4 导入 QObject:
<预><代码>>>>从 PyQt4.QtCore 导入 QObject>>>对于 dir(QObject) 中的 i:...如果我 == 'emit':...打印(真)...真的pyqtSignal
不是信号,它是用于创建信号的工厂函数,所以它当然没有 emit
属性.它只返回一个 descriptor,当绑定到 QObject 实例时将返回实际的信号对象.这意味着只有 bound 信号会有 emit
方法.
QObject.emit
方法是 pyqt 中引入新样式信号之前的遗留物,现在 已删除.只需在绑定信号上使用 emit
方法来发射它:
class SomeObject(QObject):someSignal = pyqtSignal(...)实例 = SomeObject()instance.someSignal.emit(值)
It would be helpful somebody run this code for me as a sanity check.
Python 3.3.1 (default, Apr 17 2013, 22:30:32)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>from PyQt5.QtCore import pyqtSignal
>>>for i in dir(pyqtSignal):
... if i == 'emit':
... print(True)
...
>>>
Is true returned for anyone else? Note that with a QObject import from PyQt4:
>>> from PyQt4.QtCore import QObject
>>> for i in dir(QObject):
... if i == 'emit':
... print(True)
...
True
pyqtSignal
is not a signal, it is a factory function for creating signals, so of course it doesn't have a emit
attribute. It just returns a descriptor, which when bound to a QObject instance will return the actual signal object. That means only a bound signal will have an emit
method.
The QObject.emit
method is a relic from times before new style signals were introduced in pyqt, and now has been removed. Just use the emit
method on the bound signal to emit it:
class SomeObject(QObject):
someSignal = pyqtSignal(...)
instance = SomeObject()
instance.someSignal.emit(value)
这篇关于PyQt5 在哪个模块中找到了emit 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!