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. Unable to get attribute in XmlListModel
QtWS25 Last Chance

Unable to get attribute in XmlListModel

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.1k Views
  • 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.
  • N Offline
    N Offline
    Nayar
    wrote on last edited by
    #1

    I am trying to display the current RSS feed: http://www.france24.com/en/top-stories/rss/

    Made an XmlListModel

    @ XmlListModel {
    id: feedModel
    source: "http://www.france24.com/en/top-stories/rss/"
    query: "/rss/channel/item"

        XmlRole { name: "title"; query: "title/string()" }
        XmlRole { name: "description"; query: "description/string()" }
        XmlRole { name: "img"; query: "thumbnail/@url/string()" }
    }@
    

    However, if when i call img, it contains a blank string.

    If i change the XmlRole like this
    @XmlRole { name: "img"; query: "source/@url/string()" }@

    I get the url attribute from source. But dunno why i can't get url attribute from the thumbnail

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Can you have copy of XML ? hope there 'thumbnail' and rest of the query path is path exist and correct.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nayar
        wrote on last edited by
        #3

        bq. <thumbnail url="http://scd.france24.com/en/files/imagecache/france24_ct_api_medium2/article/image/20140910 marina silva.jpg"/>
        <source url="http://scd.france24.com/en/files/imagecache/france24_ct_api_medium2/article/image/20140910 marina silva.jpg">AFP | Marina Silva campaigns in the Rocinha favela in Rio de Janeiro on August 30</source>

        Getting url from source can be done. I can't get url from thumbnail element

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          I used the same xml. I'm able to get it through thumbnail. Just pasting here on what I did. It may help you.

          ===qt.xml=========
          @<?xml version="1.0" encoding="utf-8"?>
          <current>
          <thumbnail url="http://pthinks.france24.com/en/files/imagecache/france24_ct_api_medium2/article/image/20140910 marina silva.jpg"/>
          <source url="http://scd.france24.com/en/files/imagecache/france24_ct_api_medium2/article/image/20140910 marina silva.jpg">AFP | Marina Silva campaigns in the Rocinha favela in Rio de Janeiro on August 30</source>
          </current>@

          @XmlListModel {
              id: xmlModel
              source : "qt.xml"
              query: "/current"
          
              XmlRole { name: "ThumNail"; query: "thumbnail/@url/string()" }
              XmlRole { name: "Source"; query: "source/@url/string()" }
          
              Component.onCompleted: {
                  console.log("XML Model loaded")
              }
          }
          
          ListView {
              id : showCity
              width: 180; height: 300
              model: xmlModel
              delegate: Text { text: ThumNail + ": " + Source }
          }
          

          @

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.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