PDA

View Full Version : canFetchMore is getiing called 3 times ??



prasad_N
9th October 2015, 12:24
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.

prasad_N
10th October 2015, 19:13
Any suggestions please ??

jefftee
10th October 2015, 21:07
Do you have three different views all sharing the same model?

ChrisW67
10th October 2015, 22:16
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.

prasad_N
10th October 2015, 23:34
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/63911-MVC-canFetchMore()-is-not-working-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:


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

ChrisW67
11th October 2015, 22:37
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.

prasad_N
12th October 2015, 16:07
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.


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 ??