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?
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()