'PySide.QtCore.Signal' object has no attribute 'connect'

LimitX picture LimitX · Apr 11, 2016 · Viewed 7.9k times · Source

I am using Python 3.4 with Pyside 1.2.4 and PyQt 4.8.7 and when I try to connect a Signal to a Slot it says:

'PySide.QtCore.Signal' object has no attribute 'connect'

Im am using MVC:

Model:

from PySide.QtCore import Signal
class Model(object):

    def __init__(self):
        self.updateProgress = Signal(int)

Controller:

class Controller(QWidget):
"""
MVC Pattern: Represents the controller class

"""
def __init__(self, parent=None):
    super().__init__(parent)
    self.model = Model()
    self.model.updateProgress.connect(self.setProgress)

When I look up the Class in Pycharm, by holding CTRL and click on the Signal class it looks like the following:

class Signal(object):
""" Signal """
def __call__(self, *args, **kwargs): # real signature unknown
    """ Call self as a function. """
    pass

def __getitem__(self, *args, **kwargs): # real signature unknown
    """ Return self[key]. """
    pass

def __init__(self, *args, **kwargs): # real signature unknown
    pass

@staticmethod # known case of __new__
def __new__(*args, **kwargs): # real signature unknown
    """ Create and return a new object.  See help(type) for accurate signature. """
    pass

def __str__(self, *args, **kwargs): # real signature unknown
    """ Return str(self). """
    pass

... while there are actually supposed to be the methods connect, disconnect and emit according to the PySide documentation, available at:

https://srinikom.github.io/pyside-docs/PySide/QtCore/Signal.html#PySide.QtCore.Signal.connect

Thanks for your help in advance

Answer

ekhumoro picture ekhumoro · Apr 12, 2016

The signal must be defined on the class, not the instance. The class must be a subclass of QObject, or be a mixin of such a class. So either of:

class Model(QtCore.QObject):
    updateProgress = Signal(int)

or:

class Mixin(object):
    updateProgress = Signal(int)

class Model(Mixin, QtCore.QObject):
    pass