[PyKDE] PyQt4: PyObject in SIGNAL

Phil Thompson phil at riverbankcomputing.co.uk
Tue Dec 5 12:54:57 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?

No thanks. It's now fixed but I haven't committed the change yet.

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

Also done but not yet committed. The only difference is that it's now
"PyQt_PyObject" instead of "PyObject *".

Phil




More information about the PyQt mailing list