How can I emit a PySide signal with a custom argument like python?

I am having trouble using the signals correctly in my PySide python Qt program. I want to emit a signal that takes one argument of a custom python type. documentation says

Signals can be defined using the QtCore.signal () class. Python types and C types can be passed as parameters to it.

So, I tried the following:

from PySide import QtCore from PySide.QtCore import QObject class Foo: pass class Bar(QObject): sig = QtCore.Signal(Foo) def baz(self): foo = Foo() self.sig.emit(foo) bar = Bar() bar.baz() 

But get the following error:

 Traceback (most recent call last): File "test.py", line 15, in <module> bar.baz() File "test.py", line 12, in baz self.sig.emit(foo) TypeError: sig() only accepts 0 arguments, 1 given! 

If instead I get the Foo class from QObject, the program starts without errors. But should I not pass my custom type as an argument to the signal, even if this type cannot be obtained from QObject?

This is with python 2.7.2 and PySide 1.0.4 on Windows 7.

+4
source share
1 answer

You have created an old-style class that does not seem to be supported as a signal type.

The class must inherit from another class of the new style or from the base type object :

 class Foo(object): pass 
+7
source

All Articles