在sourceforge上找到的此文档中的示例 我遇到了一个错误。
from PyQt5.QtCore import pyqtSignal, pyqtSlot
def setSignal():
signal = pyqtSignal()
signal.connect(self.myAction)
@QtCore.pyqtSlot()
def myAction():
print("signal triggered")
结果
AttributeError: 'PyQt5.QtCore.pyqtSignal' object has no attribute 'connect'
答案 0 :(得分:10)
如您所链接的文档中所述,需要在类级别定义信号:
class Foo(QObject):
signal = pyqtSignal()
def connectSignal():
self.signal.connect(self.myAction)
@QtCore.pyqtSlot()
def myAction():
print("signal triggered")