[PyQt] SIP: Retaining python class variables of derived C++ class

Nyall Dawson nyall.dawson at gmail.com
Mon Jan 7 22:38:39 GMT 2019


On Tue, 8 Jan 2019 at 02:48, Phil Thompson <phil at riverbankcomputing.com> wrote:

> > The issue is that, when I pass the Python-deriver Item instance to the pool, lose the reference to it, and then re-retreive it from the pool, the Item instance will have lost class variables set in the Item __init__ function. As I understand, this is expected, because SIP keeps a python part and a c++ part of each object, and the python part is garbage-collected when the variable gets out of scope. Is there a way to make the above logic work?
>
> Use of /Transfer/ should get the behaviour that you want. However you need to make sure you are using the right supertype for any classes that implement any sort of ownership rules. Adding the /Supertype=sip.wrapper/ class annotation to both AbstractItem and Pool classes may help.

This sounds very similar to the question asked here:
https://www.riverbankcomputing.com/pipermail/pyqt/2018-December/041177.html

But I've double checked, and the super type is indeed sip.wrapper for
both the item and registry classes. Calling sip.ispyowned before and
after transferring the item to the registry also confirms that the
ownership appears to have been transferred correctly (returns True
before the transfer, False after). But the python wrapper is still
deleted immediately as soon as it goes out of scope.

Got any other hints I could try?

Thanks,
Nyall


More information about the PyQt mailing list