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. XmlListModel: get(int index) method returns undefined.
Qt 6.11 is out! See what's new in the release blog

XmlListModel: get(int index) method returns undefined.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 2.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.
  • YashpalY Offline
    YashpalY Offline
    Yashpal
    wrote on last edited by Yashpal
    #1

    Hi, I have a problem with get(index) of XmlListModel element, the method returns nothing and so do I see this error.

    TypeError: Cannot read property 'page' of undefined
    

    I have written code something like this,

            XmlListModel{
                id: appXMLModel
                source: "qrc:/selectionMode.xml"
                query: "/rss/channel/item"
                XmlRole{ name: "type"; query: "type/string()" }
                XmlRole{ name: "page"; query: "page/string()" }
            }
    
           ListView{
                    id: list_view
                    model: appXMLModel
                    delegate: appDelegate
                    orientation: ListView.Horizontal
                }
                Component.onCompleted: {
                    var namePage = list_view.model.get(0)
                    console.log("My page " + namePage.page)
                }
            }
    

    And, my xml file looks something like this,

    <?xml version="1.0" encoding="utf-8"?>
      <rss version="2.0">
          <channel>
              <item>
                  <type>Driver</type>
                  <page>qrc:/ItemSelectedFromPathView.qml</page>
              </item>
          </channel>
      </rss>
    

    Tried ListModel against XmlListModel, things are working as expected. Now, I'm totally confused why get(index) method of XmlListModel element doesn't work as expected?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Is your pasted code correct?

      XmlListModel{
        id: appXMLModel
      

      but:

      var namePage = path_view.model.get(0)
      

      You are calling get() on different object than appXMLModel.

      (Z(:^

      YashpalY 2 Replies Last reply
      2
      • sierdzioS sierdzio

        Is your pasted code correct?

        XmlListModel{
          id: appXMLModel
        

        but:

        var namePage = path_view.model.get(0)
        

        You are calling get() on different object than appXMLModel.

        YashpalY Offline
        YashpalY Offline
        Yashpal
        wrote on last edited by
        #3

        @sierdzio Sorry, it should have been list_view there as id.

        1 Reply Last reply
        1
        • sierdzioS sierdzio

          Is your pasted code correct?

          XmlListModel{
            id: appXMLModel
          

          but:

          var namePage = path_view.model.get(0)
          

          You are calling get() on different object than appXMLModel.

          YashpalY Offline
          YashpalY Offline
          Yashpal
          wrote on last edited by
          #4

          @sierdzio So, I was able figure out the root cause. Here, I'm trying to access XmlListModel before it is in ready state. Thank you so much for your support

          1 Reply Last reply
          3
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            Cool. Have fun! :-)

            (Z(:^

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved