Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PySide: 'PySide.QtCore.Signal' object has no attribute 'emit'

Tags:

python

qt

pyside

With the following code, I get an error ('PySide.QtCore.Signal' object has no attribute 'emit') when trying to emit a signal:

#!/usr/bin/env python

from PySide import QtCore

class TestSignalClass(QtCore.QObject):
    somesignal = QtCore.Signal()

    def speak_me(self):
        self.speak.emit()
    def __init__(self):
        try:
            self.somesignal.emit()
        except Exception as e:
            print("__init__:")
            print(e)

t = TestSignalClass()

What can I do to fix this?

like image 414
quazgar Avatar asked Aug 28 '15 09:08

quazgar


1 Answers

The problem here is that although the class correctly inherits from QtCore.QObject, it does not call the parent's constructor. This version works fine:

#!/usr/bin/env python

from PySide import QtCore

class TestSignalClass(QtCore.QObject):
    somesignal = QtCore.Signal()

    def speak_me(self):
        self.speak.emit()
    def __init__(self):
        # Don't forget super(...)!
        super(TestSignalClass, self).__init__()
        try:
            self.somesignal.emit()
        except Exception as e:
            print("__init__:")
            print(e)

t = TestSignalClass()
like image 139
quazgar Avatar answered Nov 04 '22 16:11

quazgar