Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Loading a large list model with a WorkerScript

    QML and Qt Quick
    2
    4
    863
    Loading More Posts
    • 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
      uroller 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?

      1 Reply Last reply Reply Quote 0
      • A
        andre last edited by

        You could try to sync only every n iterations?

        1 Reply Last reply Reply Quote 0
        • U
          uroller 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.

          1 Reply Last reply Reply Quote 0
          • U
            uroller 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 Reply Last reply Reply Quote 0
            • First post
              Last post