[PyQt] Mis-transfer in QLayout.addWidget

Phil Thompson phil at riverbankcomputing.com
Sat Jul 12 16:11:51 BST 2014

On 08/07/2014 8:58 am, Martin Teichmann wrote:
> Hi Phil, Hi List,
> QLayout and most of its sub-classes have a method addWidget
> that add a widget to the layout. Within the sip specification,
> the widget parameter is declared /Transfer/, meaning that the
>  ownership of the widget is transferred to the layout. Unfortunately,
> Qt transfers the ownership to the parent widget of the layout,
> not the layout itself. This is unfortunate, because once the layout
>  is deleted, the widget might be garbage collected as well, while
> the parent widget still holds a reference to it. This leads to the
> weird situation of a python-created widget to loose all its python
> attributes.
> I added a script that illustrates the problem. It raises and
> AttributeError in the very last line, which should not be there.

Should be fixed in tonight's PyQt4 and PyQt5 snapshots.


More information about the PyQt mailing list