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. [Solved] Loading a ListModel dynamically
Forum Updated to NodeBB v4.3 + New Features

[Solved] Loading a ListModel dynamically

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 4.3k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    SimonJudge
    wrote on last edited by
    #1

    I have a ListModel populated from a local file (via XMLHttpRequest) during onCompleted. The list is loaded but too late for it to show in the ListView. i.e. when I add logging I can see the items are loaded after the ListView has been onCompleted.

    How can I either force the population earlier or force the model to sync. I need something like model.sync() but this is only available from .js and not .qml.

    Thanks

    Simon

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xsacha
      wrote on last edited by
      #2

      Have a look at the Twitter example in the SDK which uses the same method as you.

      For syncing, you can just re-evaluate model as whatever you have set it to.
      For example, if you have:
      @model: xmlModel@
      in your ListView, then to sync you do:
      @model = xmlModel@

      [quote author="SimonJudge" date="1292425962"]I have a ListModel populated from a local file (via XMLHttpRequest[/quote]

      By the way, why are you using ListModel instead of XmlListModel (see Twitter example)?

      "XmlListModel":http://doc.qt.nokia.com/latest/qml-xmllistmodel.html has a few advantages such as .reload() to gather the model from server again and .status() to check when data is ready.

      • Sacha
      1 Reply Last reply
      0
      • S Offline
        S Offline
        SimonJudge
        wrote on last edited by
        #3

        Thanks for the tips. I am not using XmlListModel because I am loading JSON (and from multiple JSON files to create the model)

        Thanks again

        Simon

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SimonJudge
          wrote on last edited by
          #4

          I have assigned the model after a small delay (Timer) as per the Twitter sample that does something similar for "Workaround for bug 260266". Logging shows the items are loaded after the delay but the assignment doesn't re-sync the ListView. I am sure there must be a simple way to fix this that works.

          Simon

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SimonJudge
            wrote on last edited by
            #5

            Ok, I have this working now thanks. The assignment wasn't working because I had a wrapper (item) around the ListView that wasn't passing on the assignment. I have also improved the mechanism by having a signal when the data has loaded which then causes the assignment in the view.

            Thanks

            Simon

            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