3

By trial and error I have figured out that one has to initialize pyqtSignal outside __init()__ call like this:

class BackgroundService(QObject):
    file_updated = pyqtSignal(name='file_updated')
    def __init__(self, slot_method):
        super().__init__()
        self.file_updated.connect(slot_method)  

Otherwise if I do like this

class BackgroundService(QObject):
    def __init__(self, slot_method):
        super().__init__()
        self.file_updated = pyqtSignal(name='file_updated')
        self.file_updated.connect(slot_method)  

I get an error AttributeError: 'PyQt5.QtCore.pyqtSignal' object has no attribute 'connect'

Why does the signal have to be initialized outside the constructor?

Nick Slavsky
  • 1,300
  • 3
  • 19
  • 39
  • I've asked this also before [here](http://stackoverflow.com/questions/15025686/why-does-pyside-implicitely-create-object-members-from-class-members-for-signals) – titusjan Apr 28 '17 at 00:00

0 Answers0