質問

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)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top