我在应用程序的main方法中设置了一个上下文对象:
// 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
}
}我做错了什么?
发布于 2013-01-16 23:01:28
无法从ListItemComponent中访问_corporate。
您必须以另一种方式提供访问权限:
使用: groupListItem.ListItem.view.getCorporate();
https://stackoverflow.com/questions/14357483
复制相似问题