Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 974
LimitX Avatar asked Apr 11 '16 21:04

LimitX


2 Answers

In addition to ekhumoro's answer, the class with the signal also needs to call super().__init__(). Forgetting to do so can lead to the same error.

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

    def __init__(self):
        super().__init__()  # This is required!
        # Other initialization...
like image 119
freidrichen Avatar answered Nov 16 '22 08:11

freidrichen


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
like image 42
ekhumoro Avatar answered Nov 16 '22 08:11

ekhumoro