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. Using XmlListModel to access XmlHttpRequest retrieved remote xml?
Forum Updated to NodeBB v4.3 + New Features

Using XmlListModel to access XmlHttpRequest retrieved remote xml?

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 5.0k 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.
  • C Offline
    C Offline
    cmer4
    wrote on last edited by
    #1

    Recently learned the way how to parse the http xml response using XmlHttpRequest, but someone mentioned recently in this forum that one could use XmlListModel for such parsing.

    Could someone help and describe the logic in a few words like what is the method here to use it?

    Basically when the xml is retrieved I could address is without problem via URL, but problem is I don't understand how to tell XmlListModel to wait until the XML is requested and the answer is ready. Is it done via signals or how?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Slocan
      wrote on last edited by
      #2

      See the example in the documentation here:
      http://doc.qt.nokia.com/4.7.1/qml-xmllistmodel.html

      In a nutshell, you create a new XmlListModel object, and you set its source property to the URL you want it to fetch. It will do the rest automatically. You can follow its status property to see when the data is still loading or when it is ready. But usually, you associate it with a ListView (or other View item) to display the information it downloads.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cmer4
        wrote on last edited by
        #3

        Hey Slocan, I know the way XmlListModel works - sorry I was not precise enough:

        Problem is that the source XML I am to point XmlListModel to doesn't exist until the remote server gets a xmlhttprequest posted data (api communication process). Once I post proper data to the remote server it replies back code 200 and gives me XML response which I want to parse.

        Again I can do it now with XmlHttpRequest but really want to use XmlListModel for the reply...but what should I put as source since the reply doesn't exist on the moment it loads...

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

          In that case, use XmlHttpRequest to do the post and receive the data, and then set the xml property of the XmlListModel with the data you've received. Leave the source property empty.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cmer4
            wrote on last edited by
            #5

            Hmm thats indeed what i needed;) thanks a lot [SOLVED]

            UPDATE:

            Hmm although I know the approach is right I can';t figure out what is the syntax to pass XML response over to the XmlListModel.
            Straightforwardly this one below doesn't work (gives "Cannot assign [undefined] to QString" error )
            @var xmlObject = xhr.responseXml;
            xmllistmodelparser.xml=xmlObject; console.log("passed to xmlparser")@

            How do I convert the xhr.responseXml to be suitable for XmlListModel??

            1 Reply Last reply
            0
            • R Offline
              R Offline
              remy_david
              wrote on last edited by
              #6

              Use responseText instead of responseXml it should work.

              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