Results 1 to 4 of 4

Thread: Paging a QTableView

  1. #1
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Paging a QTableView

    The application I'm working on uses a QTableView to display data from the database. The problem that I'm having is that when the application loads, the table calls the data() method for every cell, even cells that aren't visible. Since I'm displaying thousands of rows of data, this causes quite a lag on startup.

    To solve this problem I'm considering some way to "page" through the data. By that I mean that I only want to make the data() call to the backend when the row actually becomes visible. My initial idea is to determine the correct row and column counts and then build a table full of empty cells. Somehow I'd like to create an "rowIsVisible" signal that table can emit when new rows become visible and that would trigger the call to the backend. Has anyone tried anything similar to this? Any ideas/thoughts/experiences on the subject are greatly appreciated.

    Thanks,

    Jimmy

  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: Paging a QTableView

    Do you use QSqlTableModel or its subclass or a custom model? It should work fine for volume of data this big. The problem with what you want to do is that you would probably need to reimplement the view itself as well as the model as only the view knows what data is visible. The situation becomes very complicated if you want to have two views... Maybe it would better to implement some kind of cache for your data?

  3. #3
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Thanks
    13
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Paging a QTableView

    Quote Originally Posted by wysota View Post
    Do you use QSqlTableModel or its subclass or a custom model?
    I've subclassed QAbstractTableModel to make calls to a proprietary DB we're using.

    Quote Originally Posted by wysota View Post
    The problem with what you want to do is that you would probably need to re-implement the view itself as well as the model as only the view knows what data is visible. The situation becomes very complicated if you want to have two views... Maybe it would better to implement some kind of cache for your data?
    Fortunately there is only one view, so that shouldn't be an issue. I have implemented a cache, but the issue is when the application first loads before the cache is populated. The initial call to the DB takes so much time that it makes the app unusable.

    Thanks for your ideas wysota.
    Last edited by Jimmy2775; 6th November 2006 at 17:53.

  4. #4
    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: Paging a QTableView

    Maybe you could write your own database driver (if it conforms to SQL) so that you can use the standard model?

    If that's not an option, I suggest you take a look at QSqlQueryModel sources to see how Qt handles remote models without a major speed penalty.

Similar Threads

  1. Set height of QTableView to fit exact number of rows.
    By Ben.Hines in forum Qt Programming
    Replies: 3
    Last Post: 17th January 2019, 01:49
  2. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 17:13
  3. QTableView currentChanged <> selecting header
    By Everall in forum Qt Programming
    Replies: 4
    Last Post: 1st April 2009, 08:24
  4. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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.