通过反复试验,我发现必须在__init()__之外初始化pyqtSignal,如下所示:
class BackgroundService(QObject):
file_updated = pyqtSignal(name='file_updated')
def __init__(self, slot_method):
super().__init__()
self.file_updated.connect(slot_method)
否则如果我喜欢这个
class BackgroundService(QObject):
def __init__(self, slot_method):
super().__init__()
self.file_updated = pyqtSignal(name='file_updated')
self.file_updated.connect(slot_method)
我收到错误AttributeError: 'PyQt5.QtCore.pyqtSignal' object has no attribute 'connect'
为什么信号必须在构造函数之外初始化?