为什么必须将PyQt5.QtCore.pyqtSignal初始化为类变量?

时间:2017-04-27 15:07:07

标签: python python-3.x pyqt pyqt5 qt-signals

通过反复试验,我发现必须在__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'

为什么信号必须在构造函数之外初始化?

0 个答案:

没有答案