[Qt5-feedback] Add internalVariant to QModelIndex

Andre Somers andre at familiesomers.nl
Wed Jul 20 07:48:11 CEST 2011


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?
>
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.

André



More information about the Qt5-feedback mailing list