Results 1 to 6 of 6

Thread: QListView updating dynamically on demand / alternative data storage

  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 QListView updating dynamically on demand / alternative data storage

    I have a big structure which contains lots of information. This structure can be in excess of a million items in size.

    How does QListView handle having > 1 million items?

    Since I have all the data I want to display already, is it possible to subclass the control so I can read my own structure to find out what to display rather than using 'insert' and QListviews own data storage? Just seems like a waste of memory to duplicate a lot of stuff.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QListView updating dynamically on demand / alternative data storage

    The best thing is to write your own model if the standard models didn't fit your needs. Then Qt has absolutely no problem with more than 1 million items because it only fetches a few of them to display. So it saves memory. And then it fetches more if needed...

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

    Default Re: QListView updating dynamically on demand / alternative data storage

    Brilliant, thanks. I knew it was possible, but didn't know what it was called.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QListView updating dynamically on demand / alternative data storage

    Quote Originally Posted by fatjuicymole View Post
    but didn't know what it was called.
    It's called Model/View Programming and it is very very good documented at the docs: http://doc.trolltech.com/4.5/model-v...ogramming.html.
    Maybe it is enough for you using a standard model but with a custom delegate for displaying the data.

  5. The following user says thank you to Lykurg for this useful post:

    squidge (12th October 2009)

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

    Default Re: QListView updating dynamically on demand / alternative data storage

    Its fine to read the docs, but until you know what your looking for, its kinda difficult. I don't read the docs like a book and just jump to the pages of interest.

    I looked up the model programming and seemed quite easy. I threw together a class and assigned it to the widget. Works brilliant, just as I wanted it to. However, I would be interested to know how the widget knows if some data is changed. For example, if the widget is showing items 1 - 30 on a screen, and then the data for item 10 changes in the background, how does the widget know to redraw?

    Don't know if a delegate would work as I need control over the row count. I will require painting later on though as I'll need to change the font color of some items. Is this a good use of delegate? I was thinking of overriding the paint method, but not checked if thats possible yet.

  7. #6
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListView updating dynamically on demand / alternative data storage

    There is a signal dataChanged(QModelIndex, QModelIndex) in every model implementation and be sure when implementing your own mode to emit this signal everytime that some data chenges in background - this would notify view about need to redraw changed indexes (indices?).
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  8. The following user says thank you to faldzip for this useful post:

    squidge (12th October 2009)

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.