[PyQt] Keeping the wrapper alive when it would go out of scope

Nyall Dawson nyall.dawson at gmail.com
Tue Dec 4 01:42:06 GMT 2018


Hi list,

If I have a method in a class with a /Transfer/ed argument:

   void addTask( MyClass* task /Transfer/ );

and I attempt to call it from a code which looks like this:

   def scoped_function():
        t = MyClass()
        t.some_python_property = 555
        m.addTask( t )

   scoped_function()

Then the Python wrapper for t (but not the transferred cpp object) is
deleted when t goes out of scope at the end of the function call, as
expected.

Is there anyway to indicate to sip that the lifetime of the wrapper
should be bound to the cpp object, and only deleted when the cpp
object is? What I'm trying to achieve is that the wrapper, including
the python-only "some_python_property", is not cleaned up when
scoped_function() exits, and is instead only cleaned up when the
MyClass cpp base class object is deleted.

Thanks,

Nyall


More information about the PyQt mailing list