Results 1 to 5 of 5

Thread: model-view framework and canFetchmore/fetchMore

  1. #1
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default model-view framework and canFetchmore/fetchMore

    I have a huge vector (100+K elements) with elements that I want to show to the user in a QTableView. To do this I am using a custom model to serve the vector and a filter model. The user can then filter the data, which is often the first thing the user does.

    Now, whenever the user "filters" by an empty string or also when the thing starts up for the first time - then there is a long delay where the model is serving all the 100+K items to the view.


    Since the user is never interested in looking at all the 100,000 items, it would make sens to only show the first few hundred to the user and fetch more if and as needed. There appears to be a mechanism in the Qt model/view framework to do just that: canFetchMore() and fetchMore().



    however, I do not understand how these work in conjunction with a linear data structure like a vector. There is a tree based example which fetches data when the user expands a node - but I dont understand how that might work for a vector or a datastructure without such a clear cut parent-child/visible-invisible relation.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: model-view framework and canFetchmore/fetchMore

    The problem you are facing has been discussed at length in another post, and is due to the fact that the view must determine the size of every item before it can set the scrollbar thumb to the right size and position. Even if it displays only a fraction of the rows, it still must ask each one for its size.

    I suppose the only way around this is to have your model lie when asked for the row count if no filtering has been applied. The scollbar won't be the right size, but if you don't anticipate that the user will scroll through 100K entries before filtering, then it won't matter so much.

  3. #3
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: model-view framework and canFetchmore/fetchMore

    Why must it do that? All items have the same height. Can I set the scrollbar manually somehow?


    Do you have a link to that other post, I cant find it.

    But wait, the QSqlQuery model does essentially the same thing - and I just saw that here everything works fine. The scrollbar is bigger, and when the user scrolls down, it loads more items and the scrollbar becomes smaller!


    Looking at the source I do not fully understand how it does that right now though.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: model-view framework and canFetchmore/fetchMore

    Do you have a link to that other post, I cant find it.
    It's this one, I think. It's a tree view and rowCount(), but it's the same idea.

    I don't know how the QSqlQueryModel does this magic. But if you read the docs for canFetchMore() for this class, it does say that it applies only for databases that don't report the size of the result set returned by a query.

    I guess the thing to do is to override this method in your model and see where / when it is called and modify what it does to better fit the performance you need.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: model-view framework and canFetchmore/fetchMore

    My guess is that this "filter" is a QSortFilterProxyModel.
    So it has to get all source data before it knows how many rows it has.

    That's why one only uses QSortFilterProxyModel if you can't change the source model to do it there, or if the convenience of not doing it yourself is viable.

    Cheers,
    _

Similar Threads

  1. Custom ListView. Using the model / view framework.
    By plopes21 in forum Qt Programming
    Replies: 19
    Last Post: 8th May 2012, 08:43
  2. Replies: 4
    Last Post: 18th April 2012, 18:11
  3. Replies: 9
    Last Post: 26th May 2011, 12:29
  4. Data structure reference in Model/View Framework
    By jimc1200 in forum Qt Programming
    Replies: 4
    Last Post: 14th September 2009, 20:23
  5. Model/View framework: streaming data in a QTableView
    By yannickt in forum Qt Programming
    Replies: 6
    Last Post: 24th October 2008, 00:06

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.