[PyKDE] PyQt4: PyObject in SIGNAL

Phil Thompson phil at riverbankcomputing.co.uk
Sun Dec 3 14:41:01 GMT 2006

On Friday 01 December 2006 11:04 am, Giovanni Bajo wrote:
> Mark Summerfield wrote:
> >> what's the meaning of the string "PyObject" used within the signature of
> >> a signal in PyQt4? I can't seem to find it in the PyQt4 documentation.
> >> If I pass it a random python object I get core dumps and random crashes,
> >> so I assume it's not really meant for that...
> >
> > You can do Python-Python signals which Phil calls "short-circuit
> > signals" in PyQt [...]
> Yes, this is in fact documented. I guess these short-circuit signals are
> similar to the good old PYSIGNALs in PyQt3.

Similar in that arguments are not converted to C++ types and back again.

Dissimilar in that PYSIGNALS did not use Qt's signals and slots, but 
short-circuit signals do.

> But this still does not answer my question: what does "PyObject" means in
> the signature of a signal?

This was my original email: 

Also, PyQt doesn't do anything special with the reference counts of PyObject * 
arguments, so you have to make sure that the objects stay alive until all the 
slots in other threads have been run.

It might be possible to wrap a PyObject * in a C++ class that can be passed to 
qRegisterMetaType() and that handles the reference count. I think that would 
mean that you could forget the signal arguments after calling emit(). I need 
to think about that a bit more.

I will add something to the documentation.


More information about the PyQt mailing list