我有一个由JavaScript表达式(currentContainer
)定义的属性:更改Qml中的JavaScript绑定事件?
Item {
id: theContainer
property alias currentIndex: theListView.currentIndex
signal onCurrentIndexChanged()
property MyCustomCppContainer currentContainer: {
if(theListView.currentIndex >= 0)
theModel.getCustomContainer(theListView.currentIndex)
else
null
}
signal onCurrentContainerChanged() // nobody calls this signal (yet)
MyCustomCppModel {
id: theModel
}
ListView {
id: theListView
anchors.fill: parent
model: theModel
currentIndex: -1
onCurrentIndexChanged: theContainer.onCurrentIndexChanged()
/* Other properties stripped for example */
}
}
可悲的是我总是最后选定的容器,而不是当前所选择的一个:
ContainerItem {
onCurrentIndexChanged: {
//On first change, currentContainer is null
//though the first one was selected
//After selecting the second entry
//I get the result I expected last time
console.log(currentContainer.name);
}
}
我认为一个解决方案会有另一个信号currentContainer
:onCurrentContainerChanged()
。
但是谁称这个特殊信号?
你对信号'onCurrentContainerChanged'(处理器:'onOnCurrentContainerChanged')和'onCurrentIndexChanged'(处理器'onOnCurrentIndexChanged')做了什么? – derM
我想根据当前选择的项目修改交互式地图。地图本身是一个基于自定义QPainter的项目。它只支持添加和删除高亮显示的方法,所以我不能在这里简单地使用数据绑定。 –
您是否尝试过在绑定中调试代码:'property MyCustomCppContainer currentContainer:[...]'with'console.log(...)' – derM