QT Quick XmlListModel 仍然非常空
QT Quick XmlListModel remains desperately empty
我是 Qt Quick 的新手,我正在尝试将视频名称列表从 YouTube 频道检索到 XmlModelList 中。我尝试了很多想法,但列表仍然是空的。
这是我的代码:
import QtQuick 2.11
import QtQuick.Window 2.11
import QtQuick.XmlListModel 2.0
Window {
visible: true
width: 640
height: 480
XmlListModel {
id: videoListModel
source: "https://www.youtube.com/feeds/videos.xml?channel_id=UCupvZG-5ko_eiXAupbDfxWw"
query: "/feed/entry"
XmlRole { name: "title"; query: "title/string()" }
}
ListView {
orientation: ListView.Vertical
anchors.top: parent.top
model: videoListModel
delegate: Component {
id: videoDelegate
Text {
text: title
width: 200
height: 50
}
}
}
}
在 Qt Quick 中,我对明显缺少调试消息感到困惑。如何判断问题出在网络连接、文件下载、文件解析还是其他方面??
谢谢。
您可以使用errorString()方法得到
a string description of the last error that occurred if status is XmlListModel::Error
.
您只是缺少命名空间声明:
XmlListModel {
id: videoListModel
source: "videos.xml"//"https://www.youtube.com/feeds/videos.xml?channel_id=UCupvZG-5ko_eiXAupbDfxWw"
namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom';"
query: "/feed/entry"
XmlRole { name: "title"; query: "title/string()" }
}
我是 Qt Quick 的新手,我正在尝试将视频名称列表从 YouTube 频道检索到 XmlModelList 中。我尝试了很多想法,但列表仍然是空的。
这是我的代码:
import QtQuick 2.11
import QtQuick.Window 2.11
import QtQuick.XmlListModel 2.0
Window {
visible: true
width: 640
height: 480
XmlListModel {
id: videoListModel
source: "https://www.youtube.com/feeds/videos.xml?channel_id=UCupvZG-5ko_eiXAupbDfxWw"
query: "/feed/entry"
XmlRole { name: "title"; query: "title/string()" }
}
ListView {
orientation: ListView.Vertical
anchors.top: parent.top
model: videoListModel
delegate: Component {
id: videoDelegate
Text {
text: title
width: 200
height: 50
}
}
}
}
在 Qt Quick 中,我对明显缺少调试消息感到困惑。如何判断问题出在网络连接、文件下载、文件解析还是其他方面??
谢谢。
您可以使用errorString()方法得到
a string description of the last error that occurred if status is
XmlListModel::Error
.
您只是缺少命名空间声明:
XmlListModel {
id: videoListModel
source: "videos.xml"//"https://www.youtube.com/feeds/videos.xml?channel_id=UCupvZG-5ko_eiXAupbDfxWw"
namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom';"
query: "/feed/entry"
XmlRole { name: "title"; query: "title/string()" }
}