Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problems with xml
Forum Updated to NodeBB v4.3 + New Features

Problems with xml

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 322 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.
  • A Offline
    A Offline
    Abdulmueez
    wrote on last edited by
    #1

    I created an xml file that ill like to use in my qml but my model isn't getting populated.
    This is my xml code

    <?xml version = "1.0"?>
    <rss version = "2.0">
    <movieData>
    	<data>
    		<imageUrl>https://user-images.githubusercontent.com/2865368/26898832-3a492bb8-4b9b-11e7-8b51-ddf416424904.png
    		</imageUrl>
    		<name>Movie1</name>
    		<date>Date1</date>
    		<stars>*****</stars>		
    	</data>
    	<data>
    		<imageUrl>https://www.esa.int/var/esa/storage/images/esa_multimedia/images/2017/11/autumn_fireball/17255671-1-eng-GB/Autumn_fireball.jpg
    		</imageUrl>
    		<name>Movie2</name>
    		<date>Date2</date>
    		<stars>***</stars>
    	</data>	
    	<data>
    		<imageUrl>http://wallpapersdsc.net/wp-content/uploads/2016/09/Melbourne-Images.jpg</imageUrl>
    		<name>Movie3</name>
    		<date>Date3</date>
    		<stars>****</stars>
    	</data>
    	<data>
    		<imageUrl>http://cdn.spacetelescope.org/archives/images/screen/opo9229a.jpg</imageUrl>
    		<name>Movie4</name>
    		<date>Date4</date>
    		<stars>****</stars>
    	</data>
    	<data>
    		<imageUrl>http://cdn.spacetelescope.org/archives/images/screen/heic1509d.jpg</imageUrl>
    		<name>Movie5</name>
    		<date>Date5</date>
    		<stars>*****</stars>
    	</data>	
    </movieData>
    </rss>
    

    This is my qml code

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.XmlListModel 2.12
    Rectangle {
        visible: true
        width: 300
        height: 480    
        id: root;
        color: "black"
        XmlListModel{
            id: movieModel
            source: ".MovieData.xml"
            query: "/rss/movieData/data"
            XmlRole{name: "imageUrl"; query: "imageUrl/string(@url)"}
            XmlRole{name: "name"; query: "name/string()"   }
            XmlRole{name: "date"; query: "date/string()"}
            XmlRole{name: "stars"; query: "stars/string()"}
        }
    
        Component{
            id: itemDelegate
            Rectangle{
                color:"black"
                border.color: Qt.lighter(color)
                Column{
                    id:column
                    anchors.fill: parent
                    Image{
                        id: image
                        anchors.margins: 6
                        source: imageUrl
                        fillMode: Image.PreserveAspectFit
                    }
                    Text{
                        id: title
                        color:"white"
                        x: image.x
                        text:name
                    }
                    Text{
                        id: dateTitle
                        color: "white"
                        x:image.x
                        text: date
                    }
                    Text {
                        id: starsTitle
                        color: "white"
                        x: image.x
                        text: stars
                    }
                }
    
            }
        }
        ListView{
            id: listView
            anchors.fill: parent
            model: movieModel
            delegate: itemDelegate
    
        }
    }
    
    
    JonBJ 1 Reply Last reply
    0
    • A Abdulmueez

      I created an xml file that ill like to use in my qml but my model isn't getting populated.
      This is my xml code

      <?xml version = "1.0"?>
      <rss version = "2.0">
      <movieData>
      	<data>
      		<imageUrl>https://user-images.githubusercontent.com/2865368/26898832-3a492bb8-4b9b-11e7-8b51-ddf416424904.png
      		</imageUrl>
      		<name>Movie1</name>
      		<date>Date1</date>
      		<stars>*****</stars>		
      	</data>
      	<data>
      		<imageUrl>https://www.esa.int/var/esa/storage/images/esa_multimedia/images/2017/11/autumn_fireball/17255671-1-eng-GB/Autumn_fireball.jpg
      		</imageUrl>
      		<name>Movie2</name>
      		<date>Date2</date>
      		<stars>***</stars>
      	</data>	
      	<data>
      		<imageUrl>http://wallpapersdsc.net/wp-content/uploads/2016/09/Melbourne-Images.jpg</imageUrl>
      		<name>Movie3</name>
      		<date>Date3</date>
      		<stars>****</stars>
      	</data>
      	<data>
      		<imageUrl>http://cdn.spacetelescope.org/archives/images/screen/opo9229a.jpg</imageUrl>
      		<name>Movie4</name>
      		<date>Date4</date>
      		<stars>****</stars>
      	</data>
      	<data>
      		<imageUrl>http://cdn.spacetelescope.org/archives/images/screen/heic1509d.jpg</imageUrl>
      		<name>Movie5</name>
      		<date>Date5</date>
      		<stars>*****</stars>
      	</data>	
      </movieData>
      </rss>
      

      This is my qml code

      import QtQuick 2.12
      import QtQuick.Window 2.12
      import QtQuick.XmlListModel 2.12
      Rectangle {
          visible: true
          width: 300
          height: 480    
          id: root;
          color: "black"
          XmlListModel{
              id: movieModel
              source: ".MovieData.xml"
              query: "/rss/movieData/data"
              XmlRole{name: "imageUrl"; query: "imageUrl/string(@url)"}
              XmlRole{name: "name"; query: "name/string()"   }
              XmlRole{name: "date"; query: "date/string()"}
              XmlRole{name: "stars"; query: "stars/string()"}
          }
      
          Component{
              id: itemDelegate
              Rectangle{
                  color:"black"
                  border.color: Qt.lighter(color)
                  Column{
                      id:column
                      anchors.fill: parent
                      Image{
                          id: image
                          anchors.margins: 6
                          source: imageUrl
                          fillMode: Image.PreserveAspectFit
                      }
                      Text{
                          id: title
                          color:"white"
                          x: image.x
                          text:name
                      }
                      Text{
                          id: dateTitle
                          color: "white"
                          x:image.x
                          text: date
                      }
                      Text {
                          id: starsTitle
                          color: "white"
                          x: image.x
                          text: stars
                      }
                  }
      
              }
          }
          ListView{
              id: listView
              anchors.fill: parent
              model: movieModel
              delegate: itemDelegate
      
          }
      }
      
      
      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @Abdulmueez
      I know nothing about this, but:

      source: ".MovieData.xml"

      that is supposed to have that leading ., is it? It's not supposed to be ./MovieData.xml or anything else?

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

        Thanks a lot, that solved the problem

        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