Loading a large list model with a WorkerScript
-
wrote on 6 May 2014, 15:43 last edited by
I am trying to use a WorkerScript to load up a list model with a very large data set. Something like:
@
WorkerScript.onMessage = function(msg)
{
if (msg.action == 'append')
{
var model = msg.model;
for (var i = 0 ; i < msg.data.length ; i++)
{
var o = {...};
model.append(o)
model.sync();
}
}
}
@As far as I can tell I need to sync() after every append() or else the ListView doesn't display correct. I will see some of the rows repeated at the end although the count is right and the extra items can't be selected.
But the sync() call makes longing considerable slower -- from seconds to minutes. Is there a better way of doing this?
-
wrote on 6 May 2014, 16:07 last edited by
You could try to sync only every n iterations?
-
wrote on 6 May 2014, 17:14 last edited by
Good suggestion.
@
if ((i % n) == 0) model.sync();
@It seems to be working for some small n's. I'm not sure what the tipping point is.
-
wrote on 6 May 2014, 19:02 last edited by
It also seems like you can't call clear() or append() on the ListModel from the QML when you have a WorkerScript. Even with judicious use of sync() the model and view still get out of sorts.
1/4