Qt Forum

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

    Forum Updated on Feb 6th

    [SOLVED] XmlListModel not reading from query

    QML and Qt Quick
    3
    4
    2326
    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.
    • A
      Alcatraz last edited by

      Here is my XML

      @
      <Model>
      <Menu>
      <Item Image="1a46ba4ab74cb4135499cefb5448c292.png" Source="http://www.telusmobility.com/en/ON/promotions/blitz.shtml" Name="Telus">
      <SubItem Source="http://www.telusmobility.com/en/ON/smartphones/index.shtml" Name=" Smartphones"/>
      <SubItem Source="http://www.telusmobility.com/en/ON/clear_choice_voice_data/index.shtml" Name=" Rate Plans"/>
      <SubItem Source="http://www.telusmobility.com/en/ON/canada_travel/index.shtml" Name=" Coverage"/>
      <SubItem Source="http://www.telusmobility.com/en/ON/client_help/index.shtml" Name=" Support"/>
      <SubItem Source="http://www.telusmobility.com/en/ON/plans/student40.shtml?INTCMP=student_plan" Name=" Promotions"/>
      </Item>
      <Item Image="cf7ef82f8cd8d49c7b20be75962d8dc7.png" Name="Dine.To"/>
      <Item Image="dfc380961143473366a8738f3ed11444.png" Name="TourismTo"/>
      <Item Image="74c33693310631dc96a4c0360bfe2d62.png" Name="Shopping">
      <SubItem Name=" Store 1"/>
      <SubItem Name=" Store 2"/>
      <SubItem Name=" Store 3"/>
      <SubItem Name=" Store 4"/>
      </Item>
      <Item Image="82749b02b055adf6aa429cbccefe83e2.png" Source="http://rss.cbc.ca/lineup/canada.xml" Name="News">
      <SubItem Source="http://rss.cbc.ca/lineup/canada.xml" Name=" Canada"/>
      <SubItem Source="http://rss.cbc.ca/lineup/politics.xml" Name=" Politics"/>
      <SubItem Source="http://rss.cbc.ca/lineup/sports-soccer.xml" Name=" Soccer"/>
      </Item>
      <Item Image="c9c8bf6489d94a450b4f845b470ce2b0.png" Source="http://weather.yahooapis.com/forecastrss?w=2502265" Name="Weather"/>
      <Item Image="6ac44fe4974f6305c6a806721f33e4a9.png" Name="Hotels">
      <SubItem Name=" Holiday Inn"/>
      <SubItem Name=" Hilton"/>
      </Item>
      </Menu>
      </Model>
      @

      and my code is

      @
      import QtQuick 1.0

      XmlListModel {
      source: "/Media/ListModel.xml"
      query: "/Model/Menu/Item"

      XmlRole { name: "xName"; query: "Name/string()" }
      XmlRole { name: "Address"; query: "Source/string()" }
      XmlRole { name: "imagePath"; query: "Image/string()" }
      

      }
      @

      any reason why i cannot get the strings ?

      1 Reply Last reply Reply Quote 0
      • G
        GentooXativa last edited by

        Yes, you are trying to get the values inside a tag, but you need the parameter values, change your query for roles like this:

        @
        XmlRole { name: "xName"; query: "@Name/string()" }
        XmlRole { name: "Address"; query: "@Source/string()" }
        XmlRole { name: "imagePath"; query: "@Image/string()" }
        @

        the @ before variable name take the value of parameter.

        I hope this helps :)

        Jose Vicente Giner Sanchez - Senior Mobile Developer

        www.gigigo.com

        C/ Dr. Zamenhof 36bis, 1ºA 28027 Madrid
        T: +34 917431436

        1 Reply Last reply Reply Quote 0
        • D
          deimos last edited by

          Also, if it is a local xml file you should use:

          @xml: "/Media/ListModel.xml"@

          and are you sure that that path is correct ? You should use a complete path or a path relative to the executable.

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

            Forgot to say

            thanks for your help :)

            1 Reply Last reply Reply Quote 0
            • First post
              Last post