Results 1 to 3 of 3

Thread: Caching QAbstractProxyModel dilemma

  1. #1
    Join Date
    Mar 2006
    Posts
    5
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Caching QAbstractProxyModel dilemma

    Hi,

    I have a model derived from QAbstractListModel and a list view derived from QListView. The models data(..) method needs to perform some calculation each time it returns a value. Since the view queries the data very often, I thought about some sort of cache in order to have that calculation only once per model index.

    Instead of implementing the caching directly in the model, I thought to plug a proxy model (derived from QAbstractProxyModel) between my model and my view. The proxy should then somehow cache the passed data in its data(..) method.

    Now, here is my problem: Since the data(..) method is const, it has no write access to the class members, so it cannot write anything into a cache.

    Has somone here already implemented a cache proxy and solved that problem? Or is there a better way to cache something between model and view?

    Thank you,
    Alessandro

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Caching QAbstractProxyModel dilemma

    Quote Originally Posted by Alessandro
    Now, here is my problem: Since the data(..) method is const, it has no write access to the class members, so it cannot write anything into a cache.
    You could use the "mutable" keyword.

  3. The following user says thank you to jacek for this useful post:

    Alessandro (11th April 2006)

  4. #3
    Join Date
    Mar 2006
    Posts
    5
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Thumbs up Re: Caching QAbstractProxyModel dilemma

    Thank you, Jacek.
    Now, I finally learned what that mutable keyword is good for.

    -Alessandro

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.