PyQt4.QtCore.pyqtSignal object does not have the 'connect' attribute

I am having problems with a custom signal in the class I made.

Relevant Code:

self.parse_triggered = QtCore.pyqtSignal() def parseFile(self): self.emit(self.parse_triggered) 

Both of them belong to the RefreshWidget class. In the parent class, I have:

 self.refreshWidget.parse_triggered.connect(self.tabWidget.giveTabsData()) 

When I try to run the program, I get an error message:

 AttributeError: 'PyQt4.QtCore.pyqtSignal' object has no attribute 'connect' 

Help? Thanks in advance.

+42
signals pyqt pyqt4
Jun 03 2018-10-06T00:
source share
6 answers

I had the exact same problem as you.

Try moving

 self.parse_triggered = QtCore.pyqtSignal() 

from your constructor, but inside your class declaration. So instead it looks like this:

 class Worker(QtCore.QThread): def __init__(self, parent = None): super(Worker, self).__init__(parent) self.parse_triggered = QtCore.pyqtSignal() 

It should look like this:

 class Worker(QtCore.QThread): parse_triggered = QtCore.pyqtSignal() def __init__(self, parent = None): super(Worker, self).__init__(parent) 

It may not be what you are looking for, but it worked for me. I switched to old-style signals anyway, because I did not find a way to have undefined number or parameter type in new-style signals.

+70
Jun 04 2018-10-06T00:
source share

You will also receive this error message if you do not call super() or QObject.__init__() in your custom class.

Checklist for defining custom signals in a class in Qt in Python:

  • your class comes from a QObject (directly or indirectly)
  • your __init__ class calls super() (or calls QObject.__init__() directly.)
  • your signal is defined as a class variable, not an instance variable
  • the signature (formal arguments) of your signal corresponds to the signature of any slot that you will connect to the signal, for example. () or (int) or (str) or ((int,), (str,))
+52
Sep 28
source share

I recently started working with PySide (Nokia’s own version of PyQt) and saw the same behavior (and solution) with new-style custom signals. My biggest problem with the solution was that using a class variable to store the signal can hurt things when I have multiple instances of this class (QThreads in my case).

From what I could see, QtCore.QObject.__init__(self) finds the Signal variable in the class and creates a copy of this signal for the instance. I have no idea what QObject.__init__() does, but the resulting signal has the correct connect() , disconnect() and emit() methods (as well as the __getitem__() method), whereas the Signal class or autonomous signal variables, created outside A QObject-based class does not have these methods and cannot be used properly.

+9
Sep 12 '10 at 19:28
source share

To use the signal / slot system, you need to inherit the QObject class.

Here is a simple example:

 from PySide import QtCore class LivingBeing( QtCore.QObject ): bornSignal = QtCore.Signal() # initialise our signal def __init__(self,name): QtCore.QObject.__init__(self) # initialisation required for object inheritance self.bornSignal.connect(self.helloWorld) # connect the born signal to the helloworld function self.name = name # self.alive = False def summonFromClay(self): self.alive = True self.bornSignal.emit() # emit the signal def helloWorld(self): print "Hello World !, my name is %s, this place is so great !" % self.name # now try the little piece of code if __name__ == '__main__': firstHuman = LivingBeing('Adam') firstHuman.summonFromClay() 
+2
Jul 18 '13 at 10:58 on
source share

I had the same problem. I forgot that if a class uses Signals, then it should inherit from QObject. I did re-factoring and did not pay attention to it.

+2
Apr 19 '14 at 17:01
source share

Why are you connecting directly to the signal while you can do self.connect(widget, SIGNAL('parse_triggered()'), listener.listening_method) ?

where self is, for example, the form itself and can be the same as the listener

-2
Jun 04 '10 at 12:20
source share



All Articles