Results 1 to 7 of 7

Thread: canFetchMore is getiing called 3 times ??

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default canFetchMore is getiing called 3 times ??

    these days I working a lot with tree view, so one more question from tree view.

    i have canFetchMore() in my customized model. and this function calling 3 times every time when it needs (we can check this from simple tree model in Qt examples.).
    I know it might be of some internal calls. because of this I am having some performance issues.
    Is there a way I can avoid this behavior & get it called only one time when it has to.

    My prob : lets say I wanted to get top 100 items & form tree out of it, because of above behavior I am ending up with 3*100 (buffer size) items.
    Thanks :-)

  2. #2
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: canFetchMore is getiing called 3 times ??

    Any suggestions please ??
    Thanks :-)

  3. #3
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: canFetchMore is getiing called 3 times ??

    Do you have three different views all sharing the same model?
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: canFetchMore is getiing called 3 times ??

    Correct your implementation. The canFetchMore() function should indicate if more records can be fetched, it should not actually fetch them (It is declared const for a reason). The rows should only fetched if fetchMore() is called.

  5. #5
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: canFetchMore is getiing called 3 times ??

    Quote Originally Posted by ChrisW67 View Post
    Correct your implementation. The canFetchMore() function should indicate if more records can be fetched, it should not actually fetch them (It is declared const for a reason). The rows should only fetched if fetchMore() is called.
    Thanks but, I did not mentioned anywhere that I am fetching data in canfectMore().

    Problem is that canFetchMore() is calling 3 times when it supposed to call 1 time.

    For example when I expand parent Item It supposed to call 1 time, But It is calling 3 times. (This is happening even if We load all the data& show at first time return false from 2nd time as we read all data)
    We can check this behavior from simple tree example in Qt by putting qDebug() in canFetchMore() & fetchMore();



    My pro : I have 1000 child's for my parent, when I expand this parent I wanted to get 100 child's & show & load remaining data when needed. (This also has another problem That i have posted here: http://www.qtcentre.org/threads/6391...ng-as-expected
    when I expand this parent, my condition obliviously if(no.of child's already fetched < TotalChild count). this becomes true for 3 times (As canfectMore() is getting called 3 tims instead of 1 time) & i am ending up with 300 records instead of 100 records.


    Added after 22 minutes:


    Quote Originally Posted by jefftee View Post
    Do you have three different views all sharing the same model?
    No Not at all, we can check this behavior in simple tree model example
    Last edited by prasad_N; 10th October 2015 at 23:34.
    Thanks :-)

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: canFetchMore is getiing called 3 times ??

    Thanks but, I did not mentioned anywhere that I am fetching data in canfectMore().
    Not directly but you say the view calls canFetchMore() three times and...
    My prob : lets say I wanted to get top 100 items & form tree out of it, because of above behavior I am ending up with 3*100 (buffer size) items.
    That is, calling canFetchMore() three times results in 3 times the number of rows fetched in the model. You did not say that the view calls fetchMore() 3 times. If you had done that, then you would have been describing correct and expected operation. I assumed that you were describing unexpected behaviour. One obvious way that unexpected row fetching might happen is if canFetchMore() actually fetched rows.
    Problem is that canFetchMore() is calling 3 times when it supposed to call 1 time.
    No, you would like it to only call canFetchMore() once but that is not a requirement on the view, just an assumption on your part.
    If canFetchMore() returns true then the view can call fetchMore() if it wants, and the correct behaviour of the model is to fetch more rows. The view will fetch rows as it requires and probably in some convenient quantity for its internal buffering/performance/rendering purposes (i would guess 256 rows if the sql model is anything to go by). If you do not like this behaviour then you are free to implement your own view.

  7. #7
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: canFetchMore is getiing called 3 times ??

    Quote Originally Posted by ChrisW67 View Post
    If canFetchMore() returns true then the view can call fetchMore() if it wants, and the correct behaviour of the model is to fetch more rows. The view will fetch rows as it requires and probably in some convenient quantity for its internal buffering/performance/rendering purposes (i would guess 256 rows if the sql model is anything to go by).
    - I understand that because of view internal calls, canFetchMore() is getting called more than once (3 times in my case even if I return false from canfetch() or even if view is full with Items)
    - After some experiments I came to know that header data is one which causes canFetchMore() to be called (When we change headerData dynamically its calling canFetchMore() ),
    so I decided to have customized model & View for my header & It worked out Now when ever I expand an item (or when canFetchMore() supposed be called by view) instead of 3 times its getting called 2 times.
    - now its getting called twice as follows when I expand a item

    canFectMore Called with parent = QModelIndex(0,0,0xd00870,DebugTreeModel(0xcf4ec0) ) //one for the expanded Item as parent
    canFectMore Called with parent = = QModelIndex(-1,-1,0x0,QObject(0x0) ) //One for root item
    this might be of other reason like header data.

    Quote Originally Posted by ChrisW67 View Post
    If you do not like this behaviour then you are free to implement your own view.
    could let me know which functions I have to re implement for this in view ??
    Last edited by prasad_N; 12th October 2015 at 16:11. Reason: spell mistake
    Thanks :-)

Similar Threads

  1. QResizeEvent called 3 times
    By mvbhavsar in forum Newbie
    Replies: 5
    Last Post: 17th December 2014, 17:06
  2. Replies: 8
    Last Post: 11th February 2014, 11:01
  3. Qt bug? Signal emitted once, slot called multiple times
    By MattPhillips in forum Qt Programming
    Replies: 22
    Last Post: 1st December 2010, 23:32
  4. filterAcceptRows() is being called many times for same souceRow.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 19th February 2009, 04:49
  5. Replies: 0
    Last Post: 17th May 2008, 19:06

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.