[solved] How to extract global data for xml width XmlListModel



  • Hi,

    Before I have been using ListModel, now I used an XmlListModel, I want to know how to extract a global data from an xml file like is done in an example from QML Data Model :

    @ Rectangle {
    width: 200; height: 200

     ListModel {
         id: fruitModel
         property string language: "en"
         ListElement {
             name: "Apple"
             cost: 2.45
         }
         ListElement {
             name: "Orange"
             cost: 3.25
         }
         ListElement {
             name: "Banana"
             cost: 1.95
         }
     }
    
     Component {
         id: fruitDelegate
         Row {
                 Text { text: " Fruit: " + name; color: ListView.view.fruit_color }
                 Text { text: " Cost: $" + cost }
                 Text { text: " Language: " + ListView.view.model.language }
         }
     }
    
     ListView {
         property color fruit_color: "green"
         model: fruitModel
         delegate: fruitDelegate
         anchors.fill: parent
     }
    

    }@

    In this example the global var is defined at line 6. Can someone explain me how to do such thing with XmlListModel.
    Thanks



  • Hi,

    Unfortunately, there isn't yet a real elegant solution to querying XML files for non-list data (see http://bugreports.qt.nokia.com/browse/QTBUG-12953 for one possible way of handling this in the future). One thing you could try is to treat the whole file like a "list of one object", use XmlListModel to query for that object, and use model.get(0).language to obtain the value.

    Regards,
    Michael



  • Thanks for your answer.

    That what I thought. Is there any performance issue if we create many XmlListModel of the same xml file? Is the file be "re-parse" for each XmlListModel which use it ?



  • Yes, unfortunately it will be re-parsed by each model.

    Michael



  • Ok, thanks. I hope you will find a elegant way for nested xml tree.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.