Qt World Summit: Register Today!

XmlListModel: get(int index) method returns undefined.

  • 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,

                id: appXMLModel
                source: "qrc:/selectionMode.xml"
                query: "/rss/channel/item"
                XmlRole{ name: "type"; query: "type/string()" }
                XmlRole{ name: "page"; query: "page/string()" }
                    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">

    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?

  • Moderators

    Is your pasted code correct?

      id: appXMLModel


    var namePage = path_view.model.get(0)

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

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

  • @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

  • Moderators

    Cool. Have fun! :-)

Log in to reply