问题
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