我在我的应用程序的主要方法中设置了一个上下文对象:
// Load the UI description from main.qml
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(&app);
// Make the Corporate object available to the UI as context property
qml->setContextProperty("_corporate", new Corporate(&app));
但是我无法从onTouch
方法中访问 _corporate 对象,同时在 onTriggered 方法中正确访问了 _corporate 对象。这是代码:
ListView {
dataModel: _corporate.model
id: myListView
listItemComponents: [
ListItemComponent {
id: groupItemComponent
type: "groupItem"
StandardListItem {
id: groupListItem
title: qsTr ("%1").arg(ListItemData.firstRow)
description: ListItemData.secondRow
onTouch: {
_corporate.currentView = 3
}
}
}
]
onTriggered: {
_corporate.currentView = 3
}
}
我究竟做错了什么?