Results 1 to 3 of 3

Thread: Is it useful to implement fetchMore() in this context?

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

    Default Is it useful to implement fetchMore() in this context?

    Hi,

    I have a simple data model that basically encapsulates a std::vector with data. Data only exists in this vector, and the vector can potentially grow very large.

    Now I have implemented canFetchMore() and fetchMore() in so far, that I just keep an integer with the current size, and override the two fetch methods basically like so


    Qt Code:
    1. canFetchmore() { return current_size < rowCount(); }
    2. fetchMore() { current_size = std::min(current_size + 1000, rowCount()); }
    To copy to clipboard, switch view to plain text mode 


    I thought this might take some pressure of the GUI.


    But now that I think about it some more, Qt is probably smart enough to do something like this on its own. I am thinking now the fetch-more stuff only applies when I am fetching data in a very costly manner, say from SQL DB, not when I have it all here in a std::vector.


    Is this thinking right, or does it make sense to override the fetch methods like I did?

  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: Is it useful to implement fetchMore() in this context?

    Is this thinking right, or does it make sense to override the fetch methods like I did?
    Yes, and no. You already have the data in memory, so there's really nothing to fetch. The fetchMore() and canFetchMore() are intended for the expensive operations where data isn't held directly in memory until needed. If you were storing your data in a cache that can hold only part of it, then you would need to implement these methods.

    And yes, the model-view GUI is smart enough to do this on its own - QTableView, for example, will only ask for what is actually able to be visible on screen.

    I do not know about the interaction between rowCount(), canFetchMore(), and fetchMore() though. I suppose that if rowCount() returns a number smaller than the number of rows that could be displayed, the view calls canFetchMore() to determine if there is more data available, and then fetchMore() if it is.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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

    Default Re: Is it useful to implement fetchMore() in this context?

    Thanks, it indeed seems I do not need fetch-related stuff.

Similar Threads

  1. model-view framework and canFetchmore/fetchMore
    By tuli in forum Qt Programming
    Replies: 4
    Last Post: 15th August 2015, 00:53
  2. implement c++ in qml
    By askatuak in forum Qt Quick
    Replies: 9
    Last Post: 8th October 2013, 09:31
  3. Replies: 13
    Last Post: 10th April 2013, 07:15
  4. what is the best way to implement ?
    By david_itay in forum Newbie
    Replies: 1
    Last Post: 8th August 2012, 23:10
  5. QSqlQueryModel fetchMore
    By skuda in forum Qt Programming
    Replies: 0
    Last Post: 17th July 2008, 20:42

Tags for this Thread

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.