Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Loading a large list model with a WorkerScript

Loading a large list model with a WorkerScript

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    uroller
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      You could try to sync only every n iterations?

      1 Reply Last reply
      0
      • U Offline
        U Offline
        uroller
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • U Offline
          U Offline
          uroller
          wrote on last edited by
          #4

          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 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved