Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt5 - Signal : pyqtSignal no method connect

following example in this doc found on sourceforge I faced an error.

from PyQt5.QtCore import pyqtSignal, pyqtSlot

 def setSignal():        
     signal = pyqtSignal()
     signal.connect(self.myAction)

 @QtCore.pyqtSlot()
 def myAction():
     print("signal triggered")

results in

AttributeError: 'PyQt5.QtCore.pyqtSignal' object has no attribute 'connect'
like image 222
Emmanuel BRUNET Avatar asked Jun 04 '16 12:06

Emmanuel BRUNET


1 Answers

As mentioned in the docs you linked, a signal needs to be defined on class level:

class Foo(QObject):

    signal = pyqtSignal()

    def connectSignal():        
        self.signal.connect(self.myAction)

    @QtCore.pyqtSlot()
    def myAction():
        print("signal triggered")
like image 157
The Compiler Avatar answered Oct 06 '22 06:10

The Compiler