A
A
Artem Filimonov2017-07-07 07:05:48
Qt
Artem Filimonov, 2017-07-07 07:05:48

Is it possible to update a model in Qt by timing?

How often does AbstractItemModel call its (rowCount, parent, index) methods?
Is it possible to make them call on a timer?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2017-07-07
@Nvek

No, that's not possible. And in general, these parts of the model are called by a control (for example, QTreeView). The more often, the more actively we work with data.
As I understand it, you are faced with a situation: data access is slow. This means that we need to set up a cache so that rowCount, parent, index and others are executed instantly in most cases.
Well, task number two : somewhere in the wilds of the second stream, a long model update is taking place, and we want to display it in parts. This is a complex matter, and there is no universal answer.
Let's start with the fact that it is most convenient to synchronize the stream and the UI through signals-slots-emit with the Qt::QueuedConnection connection type (BlockedQueuedConnection, I think it will be a bit much). The slot will have one parameter: how many elements have already been loaded.
For each node whose sons we will load, we specify an additional field: how many elements are visible from the control. We close all complex data structures with a mutex. Since this is a complicated matter, for those objects whose capacity is limited and small, it is better not to do this - for example, if we have groups-albums-songs, you can only do this for the root element: even for productive groups like the Beatles, elements are not so lot.
We produce the following feature in the slot: rowsAboutToBeInserted, we change our additional field, rowsInserted. And so for all the elements who have added offspring.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question