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. [solved] How to extract global data for xml width XmlListModel
Forum Updated to NodeBB v4.3 + New Features

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

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

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Merinas
        wrote on last edited by
        #3

        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 ?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

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

          Michael

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Merinas
            wrote on last edited by
            #5

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

            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