[PyQt] Shouldn't an item view keep a reference to its associated model?

Phil Thompson phil at riverbankcomputing.co.uk
Fri Jul 20 11:19:50 BST 2007


On Friday 20 July 2007 10:56 am, Florent Rougon wrote:
> Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> > Yes, it reflects the Qt behaviour. Models are often shared between views
> > and so (by default) aren't owned by any particular view. If you know
> > there will only ever be one view then make it the parent of the model.
>
> I thought it should be possible to have the views keep a reference to
> their model without "owning" it, as you say. For instance:
>
>   view1.setModel(model)
>
> internally would do 'view1.model = model'
>
> and similarly,
>
>   view2.setModel(model)
>
> internally would do 'view2.model = model', so that 'model' cannot get
> garbage-collected as long as either 'view1' or 'view2' is alive.
>
> What's wrong with this approach?

Because that would become a special case.

Phil


More information about the PyQt mailing list