[Qt5-feedback] Add internalVariant to QModelIndex

Kishore Jonnalagadda kitts.mailinglists at gmail.com
Wed Jul 20 13:14:12 CEST 2011


On Jul 20, 2011 11:18 AM, "Andre Somers" <andre at familiesomers.nl> wrote:
>
> Op 19-7-2011 9:49, kai.koehne at nokia.com schreef:
> > Can you give us a use case?
> > One of my first experiences with QAbstractItemModel was writing a
'AggregateItemModel', which was basically representing several other
QAbstractItemModels as child nodes of a common root node. Think about a tree
with 'Locations' as root node, and several QFileSystemModel's as child
nodes.
> >
> > What I actually wanted to store in each QModelIndex of the aggregating
model was just the QModelIndex of the aggregated model. I couldn't do this
however directly in the QModelIndex, which is why I - like others - had to
resort to a cache in the aggregating model - an ugly and error-prone way
IMO.
> >
> >>> What do you think, would it be reasonable to add something like
> >>> internalVariant to QModelIndex?
> > With this I could have stored the QModelIndex of the aggregated model in
the QModelIndex of the aggregating model, right?

I just looked up QPersistentModelIndex and I see that's its size is just one
pointer. So it must still be possible to store a persistent index in the
internal pointer of the qmodelindex.

> Eh, no. That would have been the wrong solution. You can not store
> QModelIndexes, they are short-lived. Next time you use it, there a good
> chance it became invalid.

That really should not be an issue as the AggregateItemModel's index is also
intended to be shortlived.

Kishore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt5-feedback/attachments/20110720/301e4dd4/attachment.html 


More information about the Qt5-feedback mailing list