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. [Moved] retrieve variable from XML and show in text field
Forum Updated to NodeBB v4.3 + New Features

[Moved] retrieve variable from XML and show in text field

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 4 Posters 3.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.
  • R Offline
    R Offline
    rajan.mba
    wrote on last edited by
    #1

    Hi
    I need some help with Qt and XML. I retrieve the latitude from google API using
    @XmlListModel {
    // property int index
    id: latModel
    source: "http://maps.googleapis.com/maps/api/geocode/xml?address="+city+"&sensor=false"
    query: "/GeocodeResponse/result"
    XmlRole { name: "lat"; query: "geometry/location/lat/string()" }
    XmlRole { name: "lng"; query: "geometry/location/lng/number()" }
    XmlRole { name: "addr"; query: "formatted_address/string()" }
    }@
    However when I use it to retrieve the 'lat' variable to put in text, I get 'ReferenceError: Can't find variable: lat'. I am able to use the same variable in a list view without any problem. Pl let me know how to retrive the variable 'lat' and display in the text field.
    @Text {
    id: lattxt
    x: 10
    y: 200
    width: 100
    height: 30
    color: "#360414"
    text: lat
    font.bold: true
    font.pixelSize: 40
    }
    @
    THANKS IN ADVANCE

    OVISTORE PUBLISHER
    FORUM NOKIA MEMBER SINCE 18 Feb 2009

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      You can not use XmlListModel in this way. A model is supposed to be used with a view, and the XmlRoles will be made available to delegates in that view. Outside of that scope, it is meaningless.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ad5xj
        wrote on last edited by
        #3

        Try putting your text item in a listview as a delegate that changes the text per the docs:

        @
        XmlListModel {
        id: xmlModel
        source: "http://www.mysite.com/feed.xml"
        query: "/rss/channel/item"

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

        }
        @

        @
        ListView {
        width: 180; height: 300
        model: xmlModel
        delegate: Text { text: title + ": " + pubDate }
        }
        @

        Of course you use your text and xml role in the example.

        The example for the QML Twitter project is a good illustration as to how XML Roles get displayed.

        Ken AD5XJ

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rajan.mba
          wrote on last edited by
          #4

          Thanks for the reply. I will look into it. Sorry I didn't notice the QML thread so I posted my question under Qt.

          OVISTORE PUBLISHER
          FORUM NOKIA MEMBER SINCE 18 Feb 2009

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

            "LINK":http://permalink.gmane.org/gmane.comp.lib.qt.qml/555

            Basically you can do as advised though this is far from optimal...

            @XmlListModel {

            source: "http://xkcd.com/100/";
            query: "/html/head"
            namespaceDeclarations: "declare default element namespace 'http://www.w3.org/1999/xhtml';"
            
            XmlRole { name: "image"; query: "title/string()" }
            
            onStatusChanged: {
                if (status == XmlListModel.Ready)
                    titleText.text = get(0).image;
            }
            

            }

            Text {
            id: titleText
            }@

            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