Qt / QML:XmlListModel无法读取xml文件

时间:2018-01-13 06:34:55

标签: xml qt qml

我无法使用XMLListModel读取简单的xml文件。在控制台中始终显示以下错误。

  

标记中的错误FODC0002:trolltech.com,2007:QtXmlPatterns:QIODeviceVariable:src,第1行,第38列:不支持的XML版本。

XML文件:

<?xml version="1.1" encoding="utf-8"?>
<rss version="2.0">
<channel>
    <item>
        <title>A blog post</title>
        <pubDate>Sat, 07 Sep 2010 10:00:01 GMT</pubDate>
    </item>
    <item>
        <title>Another blog post</title>
        <pubDate>Sat, 07 Sep 2010 15:35:01 GMT</pubDate>
    </item>
</channel>

代码:

Window {
visible: true
width: 640
height: 480

XmlListModel{
    id: xmlModel
    source: "Test.xml"
    query: "/rss/channel/item"
    XmlRole { name: "title"; query: "title/string()" }
    onStatusChanged: {
        console.log("Status Changed...." , status)
        console.log(errorString())
    }
}

MouseArea{
    anchors.fill: parent
    onClicked: {
        console.log(xmlModel.count)
        for(var i = 0 ; i < xmlModel.count ; i++)
        {

            var name = xmlModel.get(i).title
            console.log(name)
        }
    }
}}

0 个答案:

没有答案
相关问题