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

Denis Rouzaud denis.rouzaud at gmail.com
Tue Dec 4 02:03:14 GMT 2018


Hi Nyall,

Isn't KeepReference what you are looking for?

Denis

On Mon, 3 Dec 2018, 21:43 Nyall Dawson, <nyall.dawson at gmail.com> wrote:

> 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
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-- 

Denis Rouzaud
denis at opengis.ch  <denis at opengis.ch>
+41 76 370 21 22
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20181203/1d103bec/attachment-0001.html>


More information about the PyQt mailing list