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] XmlsListModel.get() won't work.

[Solved] XmlsListModel.get() won't work.

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 2.4k 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.
  • AlicemirrorA Offline
    AlicemirrorA Offline
    Alicemirror
    wrote on last edited by
    #1

    ... and my obvious question is: what I have missed?

    I have xml feeds that should be managed as data. Due to a workaround of the "QT-BUG 12953":https://bugreports.qt.nokia.com/browse/QTBUG-12953 I am trying to provide a definitely way to manage them using QML and Js. I have tried to manage one of my xml files with not so good results. So, I have created a silly xml file and the results are the same as I explain below:

    The xml file is the following test.xml (just copied from the XmlListModel documentation):
    @
    <?xml version="1.0" encoding="utf-8"?>
    <test version="2.0">
    <channel>
    <item>
    <title>A blog post</title>
    </item>
    <item>
    <title>Another blog post</title>
    </item>
    </channel>
    </test>
    @
    At this point I create the XmlListModel as follows:
    @
    XmlListModel{
    id: quicklinksXML
    source: "../data/download/config/test.xml"
    query: "/test/channel/item"

        XmlRole { name: "title"; query: "title/string()" }
    }
    

    @
    Then, from a js I try to get a value from the list model:
    @
    var test = quicklinksXML.get(0).title;
    console.log("<<<XML>>> = " + test)
    @
    (always following the example of the documentation)

    At this point the question is: why I have always a [Undefined] result?

    The second but not less important question is: having a xml field in the format
    @
    ...
    <field parameter="value">
    Data of the fiels
    </field>
    ...
    @
    Do you know if there is a way to read the parameter="value" content, that is not a field but part of the xml element?

    Thank to all.

    Enrico Miglino (aka Alicemirror)
    Balearic Dynamics
    Islas Baleares, Ibiza (Spain)
    www.balearicdynamics.com

    1 Reply Last reply
    0
    • G Offline
      G Offline
      geronik
      wrote on last edited by
      #2

      What about the status code of your model ?

      @var sc = quicklinksXML.status; conslole.log(sc + " error code " + quicklinksXML.errorString)@

      About the parameter something like the code below should work,

      @XmlRole { name: "field"; query: "field/@parameter" }@

      1 Reply Last reply
      0
      • AlicemirrorA Offline
        AlicemirrorA Offline
        Alicemirror
        wrote on last edited by
        #3

        Mmm... The error code is managed by a case, because I will see what are the steps: loading, the data ready, that's when I try to read. The role as I wrote above is as I saw in the example. Why do you suggest the field/@parameter ? As I know it should be the content type of the field...

        Enrico Miglino (aka Alicemirror)
        Balearic Dynamics
        Islas Baleares, Ibiza (Spain)
        www.balearicdynamics.com

        1 Reply Last reply
        0
        • G Offline
          G Offline
          geronik
          wrote on last edited by
          #4

          I was trying to answer to the second question of yours, I thought you needed the value of the property parameter of the tag named field.

          1 Reply Last reply
          0
          • AlicemirrorA Offline
            AlicemirrorA Offline
            Alicemirror
            wrote on last edited by
            #5

            Yes exctly. Sorry if I was unclear.

            I am interested to this question from the QML document side, I saw that if the problem can't be solved I will manage a class in C++ but from QML / Js is best.

            Thank you again.

            Enrico Miglino (aka Alicemirror)
            Balearic Dynamics
            Islas Baleares, Ibiza (Spain)
            www.balearicdynamics.com

            1 Reply Last reply
            0
            • AlicemirrorA Offline
              AlicemirrorA Offline
              Alicemirror
              wrote on last edited by
              #6

              The problem was solved with some tricks and some workarounds: using the get() it is not sufficient when the XmlListModel.status is Ready. As a matter of fact, it is possible that in the exact instant when you call the get() the Ready condition is true but the data for some reason are not yet available to the QML. Thus it should be added a control if the get() value is Undefined (=null) or not.
              Excluding this, all the suggestions of @geronik was correct. The best practice is managing a onStatusChange event checking the Ready condition in conjunction with a XmlListModel.get(0).parameter control for != null

              I am preparing a small component based on the XmlListModel to simplify the management of the xml files when these should be treated in a different way than lists.

              Enrico Miglino (aka Alicemirror)
              Balearic Dynamics
              Islas Baleares, Ibiza (Spain)
              www.balearicdynamics.com

              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