1
我见过其他人使用“onSourceChanged:reload();”信号在XmlListModel中,但我找不到任何有关它的信息(并且它不适合我)。 xml文件更新快(每秒1或2次)。 我也尝试过用我自己的xml文件并手动编辑它,但没有成功。如何在间隔或数据更改时从XmlListModel中刷新数据?
如何更新ListView/XmlListModel,以便我的应用程序始终显示正确的数据? (这是在间隔时间或来源改变时)。
我XmlListModel文件(ICDModel.qml)
import QtQuick 2.0
import QtQuick.XmlListModel 2.0
XmlListModel {
source: "http://192.168.1.103:89/FunctionGenerator/FuncGen1.xml"
query: "/Component/Signals/Signal"
onSourceChanged: reload();
XmlRole { name: "Name"; query: "@Name/string()" }
XmlRole { name: "Description"; query: "@Description/string()" }
XmlRole { name: "Value"; query: "@Value/string()"; isKey: true }
}
内main.qml
ListView {
id: listView
anchors.fill: parent
spacing: 10
model: ICDModel2 {}
delegate: contactDelegate
highlight: highlightBar
highlightFollowsCurrentItem: false
focus: true
}
最后委托(也在里面main.qml)ListView控件
Component {
id: contactDelegate
Item {
id: wrapper
height: 40; width: parent.width
Column {
Text { text: '<b>Name:</b> ' + Name }
Text { text: '<b>Description:</b> ' + Description }
Text { text: '<b>Value:</b> ' + Value }
}
states: State {
name: "Current"
when: wrapper.ListView.isCurrentItem
PropertyChanges { target: wrapper; x: 20 }
}
transitions: Transition {
NumberAnimation { properties: "x"; duration: 200 }
}
MouseArea {
id: mouse_area1
anchors.fill: parent
hoverEnabled: false
onClicked: {
wrapper.ListView.view.currentIndex = index
}
}
}
}
你在哪里改变源代码?我只看到一个静态源,所以“onSourceChanged”信号不会被调用!? – Xander
你是对的@Xander。不能相信我没有意识到“onSourceChanged”只在实际的源URL更改时被调用,而不是从源收集的值。 (愚蠢的错误)。一位朋友找到了解决方案,所以我应该以某种方式解决这个问题。谢谢! – user2750342
你可以回答你自己的问题,并接受它作为答案(如果别人有类似的问题)。 :) – Xander