[PyQt] Shouldn't an item view keep a reference to its associated
model?
Florent Rougon
f.rougon at free.fr
Fri Jul 20 10:56:38 BST 2007
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?
Thanks.
--
Florent
More information about the PyQt
mailing list