+ Reply to Thread
Results 1 to 2 of 2

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

  1. #1
    Join Date
    Jul 2012
    Thanked 7 Times in 7 Posts
    Qt products

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


    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
    Alameda, CA, USA
    Thanked 554 Times in 544 Posts
    Qt products
    Unix/X11 Windows Android

    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.

+ Reply to Thread

Similar Threads

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

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts