PyQt5 in what module is the emit method found?

落爺英雄遲暮 提交于 2020-01-07 05:03:08

问题


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

回答1:


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)


来源:https://stackoverflow.com/questions/17581506/pyqt5-in-what-module-is-the-emit-method-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!