Loading a large list model with a WorkerScript



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



  • You could try to sync only every n iterations?



  • 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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.