Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

XMLListModel Related Questions



  • Hello

    A while ago i needed to create a program which uses xml files. But i have never worked with neither xml nor json files. So i don't have much of an idea about them, which is why i decided to download a few xml files from the internet and work with them.

    Anyways here are my questions regarding xml files

    1. I tried loading which was very succesfull, but i couldn't read a single value from it although playing around with it for while. How can i read the values and display them on screen.

    2. Is it possible to write values after they are changed by the user?

    3. Can i group these together with, like one-key-one-value. So i can have them better controlled?

    Thanks in advance for any help.

    Here is my code and xml file:

    import QtQuick 2.7
    import QtQuick.Window 2.2
    import QtQuick.XmlListModel 2.0
    
    Window {
        visible: true
        width: 1200
        height: 600
        title: qsTr("Hello World")
    
        MainForm {
            anchors.fill: parent
            color: "#141414"
    
            ListView {
                spacing: 5
    
                model: xmlModPlist
    
                delegate: Text {
                    color: "#ffffff"
                    text: key
                    font.family: "Calibri"
                    font.pointSize: 16
                    verticalAlignment: Text.AlignVCenter
                    horizontalAlignment: Text.AlignHCenter
                    antialiasing: true
                }
            }
    
            XmlListModel {
                id: xmlModPlist
                source: "qrc:/Res/particle.plist"
                query: "/plist/dic"
    
                XmlRole {name: "key"; query: "key/string()"}
            }
        }
    }
    
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
      <dict>
        <key>maxParticles</key>
        <integer>500</integer>
        <key>angle</key>
        <real>90</real>
        <key>angleVariance</key>
        <real>2</real>
        <key>duration</key>
        <real>-1</real>
        <key>blendFuncSource</key>
        <integer>770</integer>
        <key>blendFuncDestination</key>
        <integer>1</integer>
        <key>startColorRed</key>
        <real>1</real>
        <key>startColorGreen</key>
        <real>0.31</real>
        <key>startColorBlue</key>
        <real>0</real>
        <key>startColorAlpha</key>
        <real>0.62</real>
        <key>startColorVarianceRed</key>
        <real>0</real>
        <key>startColorVarianceGreen</key>
        <real>0</real>
        <key>startColorVarianceBlue</key>
        <real>0</real>
        <key>startColorVarianceAlpha</key>
        <real>0</real>
        <key>finishColorRed</key>
        <real>1</real>
        <key>finishColorGreen</key>
        <real>0.31</real>
        <key>finishColorBlue</key>
        <real>0</real>
        <key>finishColorAlpha</key>
        <real>0</real>
        <key>finishColorVarianceRed</key>
        <real>0</real>
        <key>finishColorVarianceGreen</key>
        <real>0</real>
        <key>finishColorVarianceBlue</key>
        <real>0</real>
        <key>finishColorVarianceAlpha</key>
        <real>0</real>
        <key>startParticleSize</key>
        <real>70</real>
        <key>startParticleSizeVariance</key>
        <real>49.53</real>
        <key>finishParticleSize</key>
        <real>10</real>
        <key>finishParticleSizeVariance</key>
        <real>5</real>
        <key>sourcePositionx</key>
        <real>300</real>
        <key>sourcePositiony</key>
        <real>300</real>
        <key>sourcePositionVariancex</key>
        <real>0</real>
        <key>sourcePositionVariancey</key>
        <real>0</real>
        <key>rotationStart</key>
        <real>0</real>
        <key>rotationStartVariance</key>
        <real>0</real>
        <key>rotationEnd</key>
        <real>0</real>
        <key>rotationEndVariance</key>
        <real>0</real>
        <key>emitterType</key>
        <integer>0</integer>
        <key>gravityx</key>
        <real>0</real>
        <key>gravityy</key>
        <real>0</real>
        <key>speed</key>
        <real>100</real>
        <key>speedVariance</key>
        <real>30</real>
        <key>radialAcceleration</key>
        <real>0</real>
        <key>radialAccelVariance</key>
        <real>0</real>
        <key>tangentialAcceleration</key>
        <real>0</real>
        <key>tangentialAccelVariance</key>
        <real>0</real>
        <key>maxRadius</key>
        <real>100</real>
        <key>maxRadiusVariance</key>
        <real>0</real>
        <key>minRadius</key>
        <real>0</real>
        <key>rotatePerSecond</key>
        <real>0</real>
        <key>rotatePerSecondVariance</key>
        <real>0</real>
        <key>particleLifespan</key>
        <real>2</real>
        <key>particleLifespanVariance</key>
        <real>1.9</real>
        <key>textureFileName</key>
        <string>texture.png</string>
      </dict>
    </plist>
    


  • Okay, so i learned a few things.

    It seems writing to xml files using QML is not possible, but by using C++ side of things it can be done. So my questions are now invalid it seems.


Log in to reply