Answer the question
In order to leave comments, you need to log in
How should the model and QSortFilterProxyModel interact correctly?
Greetings!
The situation is as follows:
There is a model based on QAbstractItemModel, since there is a lot of data, I get them using the canFetchMore and fetchMode designed for this,
and when the model is simply displayed in the ListView (qml), everything is fine, the data is loaded as it scrolls.
Now I hang a proxy on this model from above, based on the QSortFilterProxyModel
in it, I select rows for the test (by redefining filterAcceptsRow) by some field, it doesn’t matter.
Then the problems begin.
When filtering is set, not all possible values are displayed in the view!
those. only those currently loaded into fetchMore are displayed.
Those. in fetchMore I load 100 records, none are displayed, because target values will be loaded starting from 500
. it is logical that the view does not consider it necessary to load more. everything fits and does not need to be scrolled, but the proxy model does not consider it necessary to load further, or somehow inform the main model - I need records with these values.
Tell me, please, how to be?
No, I agree that it would be best to select the desired values through a request to the database, so as not to load too much,
but then how is it better to make a connection with the main model?
those. for example, in the fetchRow of the main model, I loaded records from 0 to 100, in the proxy model, you need to select those that are located starting from 500, ok, I tell the main model - load records with these values, if any.
Ok, I'm loading.
But the following problem arises - if a record for example 555 is added to the model, then when the view is scrolled, it will ask for records from 500 to 600 and then I will add record 555 again. it will be a duplication.
Remember the records that loaded? something smells like a crutch.
Maybe there is a beautiful way out of the situation?
Thanks for the tips on what to look for!
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question