[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: Transferring ownership of lists of pointers
From: Phil Thompson <phil () riverbankcomputing ! com>
Date: 2023-02-28 14:03:22
Message-ID: eadd9f16cbd747c3338941d92cb4cbcf () riverbankcomputing ! com
[Download RAW message or body]
On 28/02/2023 01:30, Nyall Dawson wrote:
> On Mon, 27 Feb 2023 at 19:05, Phil Thompson
> <phil@riverbankcomputing.com> wrote:
>
>> If by 'list' you mean 'QList' then it should work. As ever a short
>> complete example that demonstrates the problem would help.
>
> I've done some deeper digging, and I believe the difference is when
> /Transfer/ is used with a list of objects as part of the "parent"s
> constructor.
>
> I.e. in this example the constructor fails to transfer ownership,
> while "setChildren" does correctly transfer ownership:
>
> cpp code:
>
> class MyChild
> {
> public:
> };
>
> class MyParent
> {
> public:
> MyParent( const QList< MyChild* >& children ) : mChildren(
> children ) {}
> ~MyParent() { qDeleteAll( mChildren ); }
> void setChildren( const QList< MyChild* >& children ) {
> qDeleteAll( mChildren ); mChildren = children; }
> private:
> QList< MyChild * > mChildren;
> };
>
> .sip file:
>
> class MyChild
> {
> public:
> };
>
> class MyParent
> {
> public:
> MyParent( const QList< MyChild* >& children /Transfer/ );
> ~MyParent();
> void setChildren( const QList< MyChild* >& children /Transfer/ );
> };
>
>
> This python code works correctly:
>
> p = MyParent([])
> p.setChildren([MyChild(), MyChild()])
> del p
>
> But this crashes:
>
> p = MyParent([MyChild(), MyChild()])
> del p
This should be fixed in the next SIP snapshot. You will also need to
update the PyQt5/PyQt6 sip module.
Thanks,
Phil
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic