PDA

View Full Version : Storing additional data for each item within QAbstractProxyModel



squidge
2nd December 2009, 20:12
For each item displayed, I wish to fetch more information. Thats no problem, but for performance reasons, I also wish this data to be cached.

Due to the fact that the proxy model can be sorted I can't just use the index as a reference into this cache, as it could change at any time. Therefore I use the index returned from mapToSource, as thats guaranteed to always be the same regardless of where the item is in the proxy.

I'm wondering if there's a better way of combining data with an item that would work in such a situation? Calling mapToSource for every single item seems wasteful of processor usage when all I care about is a unique number for each item.

wysota
3rd December 2009, 10:20
You should never store QModelIndex objects, they are to be treated as volatile. Think about applying two levels of proxy - then you can for example use QModelIndex::internalPointer() or QModelIndex::internalId() to make sure caching works properly.