[PyQt] adding signal from class method?

Phil Thompson phil at riverbankcomputing.com
Thu Aug 14 08:45:07 BST 2014


On 14/08/2014 12:03 am, Erik Hvatum wrote:
> Hi everybody,
> 
> Is it possible to add a signal to a pyqt class from a class method
> (decorated with @classmethod) or from outside of the class?  I am 
> somewhat
> surprised that the following does not work:
> 
> class C(Qt.QObject):
>     def __init__(self):
>         super().__init__()
> 
> C.fooSignal = Qt.pyqtSignal(int, name="fooSignal")
> c = C()
> c.fooSignal.emit(1)
> !!!! AttributeError: 'C' does not have a signal with the signature
> fooSignal(int)

C++ isn't as dynamic as Python. The QMetaObject (which contains the 
signal definitions) is created when the class is defined and cannot be 
modified later.

Phil


More information about the PyQt mailing list