xml - QML XmlListModel 递归(?)查询
问题描述
我有一个看起来像这样的 xml:
<?xml version="1.0" encoding="UTF-8" ?>
<root>
<plcValue>dgIconXY11.value</plcValue>
<state>Grip1IsClamped.png</state>
<state>Grip1IsMove.png</state>
</root>
我用这个查询这个xml:
import QtQuick 2.12
import QtQuick.XmlListModel 2.12
XmlListModel {
id: xmlIconModel
property int stateNr
source: "listViewIcons.xml"
query: "/root"
XmlRole {
name: "sPLCval"
query: "plcValue/string()"
}
XmlRole {
name: "sState"
query: "state[" + stateNr + "]/string()"
}
}
然后使用它:
import QtQuick 2.12
Rectangle {
id: iconGridBg
property int currIndex
width: 36
height: 36
color: "black"
Image {
id: iconListImg
height: 36
width: 36
source: sState
}
}
问题:我想使用 plcValue 字符串并从代码中获取它的值,并且使用该值我想获取同一分支的第 n 个状态值。
所以我的dgIconXY11.value
代码中有一个地方。它的值将是一个 int 并且基于该 int 如果它是例如: 1 我想获得第一个状态,如果它是 2 第二个状态。
解决方案
所以,我没有成功使用递归查询。解决方法是有两个(或更多)XmlListModel
s。首先获取第二个查询的信息,就像sPLCval
我的情况一样。
推荐阅读
- python - 使用 cv2.videowriter 时如何处理文件名读取约定
- python - 为什么我在 pine 脚本上不断收到“未声明的标识符”错误消息?
- sql - 如果不存在用户定义的索引,where 子句会提高性能吗?
- python - Python 导入子文件夹和父文件夹
- python - 为什么我系统上的所有 CuPy 函数都比它们的 NumPy 对应函数慢?
- python - 屏蔽 4D 布尔 numpy 数组的最快方法
- kubernetes - 查看低于 5 天的错误 pod
- spring-boot - 在两个不同的数据源中持久化时如何处理事务和回滚
- git - 如何更改最后一次 github 提交的作者?
- javascript - 显示错误方向的希伯来文本开头和结尾的特殊字符