Results 1 to 2 of 2

Thread: Storing additional data for each item within QAbstractProxyModel

  1. #1
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Storing additional data for each item within QAbstractProxyModel

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Storing additional data for each item within QAbstractProxyModel

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.