[PyKDE] PyQt4: PyObject in SIGNAL

Giovanni Bajo rasky at develer.com
Sun Dec 3 23:55:20 GMT 2006


Phil Thompson wrote:

>> But this still does not answer my question: what does "PyObject" means in
>> the signature of a signal?
> 
> This was my original email: 
> http://mats.imk.fraunhofer.de/pipermail/pykde/2006-February/012358.html

In this mail, you said that SIGNAL("foo(PyObject*)") and SIGNAL("foo") are the 
same. In my application, the latter does work, but the former was causing a 
random crash in the code (the object that arrived in the slot was "wrong", it 
had a different id() than the object that was being emitted, and basically 
caused a core dump as soon as you accessed it somehow).

I guess there is a bug somewhere. Do you need a repro recipe?

> 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.

In the crash experimented above, there were no threads involved. There was a 
QProcess, but I don't think that changes things much.

> 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 think something along these lines would be great.
-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com




More information about the PyQt mailing list