QListView: model/view: is it possible to disable the hundreds/thousands of data() calls
It is the first time I working with Qt and I found it quite nice but I have now a problem.
Iam implementing a listview with the model/view concept.
My model inherits the QAbstractListModel and I implemented the virtual rowCount() and data() function.
During development I changed something in my model and this change was immediately shown in the gui.
I thought I had to manually call datachanged() to make a update so I implemented a console output inside data() to see whats going on.
It looks like the data() function is called 5 times for each element initially and also when the mouse cursor goes inside/or outside.
If I move the mouse from the left side to the right side of an element I have up to 250 data() calls for the same element.
My problem is that I have to handle with a very large amount of elements and it is maybe in the future also possible that a data() call can get really expensive due to network/database costs.
Is it possible to change this behavior?
I only want data() calls/updates if I manually trigger it.
What is the Qt strategy regarding very large list/tree views.
Have you prepared your own view also or you use some existing ones?
If you use exising views, which one?
I use the normal QListView.
Solved my problem.
I had a wrong impression of the design of QAbstractListModel.
Did also a design error in data() function that lead to performance problems.
after read your text, i think that maybe you can also connect directly to your database and use a QSqlQueryModel and then mount it in your view for the column you choose. Also, with this, you could easily get data on itm selected... and put them where you want in some other place independantly (a detalied read content at time you click on column of the listview for exemple).
The QSqlQueryModel is really nice and easy to use.
[quote author="Fenrix" date="1420919329"]What is the Qt strategy regarding very large list/tree views.[/quote]The Qt strategy is to incrementally populate the model.
Override fetchMore() and canFetchMore(). Search for these functions in the pages below:
Also: there is no avoiding data() being called often. It will be called for each and every cell, but muliple times for the different roles as well. So, your implementation better be efficient. Use caching, construct your index a way that allows you to get to your data fast, whatever you can do speed it up.
More tips: try to avoid a series of consecutive updates. Instead, make bigger updates in one go. And you do need to announce changes to data by emitting the dataChanged signal.