Transferring ownership of lists of pointers

Phil Thompson phil at riverbankcomputing.com
Mon Feb 27 09:05:31 GMT 2023


On 27/02/2023 02:36, Nyall Dawson wrote:
> Hi list,
> 
> I've a question regarding the correct way to transfer ownership of a 
> list
> of objects. I've searched for examples in the PyQt sip files, and the 
> best
> I can find is from QWinJumpList which indicates that a simple 
> /Transfer/
> annotation should work for transferring all the list items:
> 
>     QWinJumpListCategory *addCategory(const QString &title,
>             const QList<QWinJumpListItem *> items /Transfer/ =
> QList<QWinJumpListItem *>());
> 
> (from qwinjumplist.sip)
> 
> However, in my tests, just adding /Transfer/ to a list argument doesn't
> correctly transfer all the ownership of these objects and I get crashes 
> as
> soon as one of the python list members gets garbage collected.
> 
> Should this work? Or is there a better/safer/"canonical" way to 
> transfer
> lists of objects in sip?

If by 'list' you mean 'QList' then it should work. As ever a short 
complete example that demonstrates the problem would help.

Phil


More information about the PyQt mailing list