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

Hai, I'm unable to display data from xmllistmodel to main.qml?



  • main.qml
    import QtQuick 2.0
    import QtCharts 2.0
    import QtQuick.XmlListModel 2.0
    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import QtQml.Models 2.15

    ApplicationWindow {
    width: 1000
    height: 1000
    visible: true
    title: qsTr("Model")

    ChartView {
        id: chartView
        title: "Driver Speeds, lap 1"
        anchors.fill: parent
        legend.alignment: Qt.AlignTop
        animationOptions:ChartView.AllAnimations
        antialiasing: true
    
    }
    XMLLIST{
        id:list
    }
    
    
    Component {
        id: fruitDelegate
        Row {
            spacing: 10
            Text { text: speedTrap }
            Text { text:  driver }
            Text { text:  speed }
        }
    }
    
    ListView {
        anchors.fill: parent
        model: list
        delegate: fruitDelegate
    }
    

    }

    xmllist.qml
    import QtQuick.XmlListModel 2.0
    XmlListModel {
    
        // Hard-coded test data
        xml: "<results><row><speedTrap>0</speedTrap><driver>Fittipaldi</driver><speed>104.12</speed></row>"
            +"<row><speedTrap>0</speedTrap><driver>Stewart</driver><speed>106.12</speed></row>"
            +"<row><speedTrap>0</speedTrap><driver>Hunt</driver><speed>106.12</speed></row>"
    //![1]
            +"<row><speedTrap>1</speedTrap><driver>Fittipaldi</driver><speed>115.12</speed></row>"
            +"<row><speedTrap>1</speedTrap><driver>Stewart</driver><speed>114.12</speed></row>"
            +"<row><speedTrap>1</speedTrap><driver>Hunt</driver><speed>115.12</speed></row>"
            +"<row><speedTrap>2</speedTrap><driver>Hunt</driver><speed>165.23</speed></row>"
            +"<row><speedTrap>2</speedTrap><driver>Fittipaldi</driver><speed>175.23</speed></row>"
            +"<row><speedTrap>2</speedTrap><driver>Stewart</driver><speed>168.23</speed></row>"
            +"</results>"
    //![2]
        query: "/results/row"
    
        XmlRole { name: "speedTrap"; query: "speedTrap/string()" }
        XmlRole { name: "driver"; query: "driver/string()" }
        XmlRole { name: "speed"; query: "speed/string()" }
        }
    
    
    


  • @Joshika_Namani works for me:

    e12aeabf-f7fd-4809-b858-c8c169314cdd-image.png

    I changed a couple of things:

    1. XMLLIST in main.qml -> XmlList
    2. Saved the 'xmllist.qml' as 'XmlList.qml'
    3. Got rid of the chart stuff.


  • @Bob64
    Thanks for your reply, but I'm getting error like Xmllist is not a type.



  • Its working now, due to main.cpp it didn't work. Thanks a lot. can I place those speed values in lineseries chart instead of Listview can i take lineseries chart