Search code examples
qmlblackberry-10

Accessing context property from within an onTouch method


I set a context object in the main method of my app:

// 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));

But I cannot access the _corporate object from within the onTouch method, while at the same time the _corporate object is properly accessed in the onTriggered method. Here's the code:

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

                }
}

What am I doing wrong?


Solution

  • _corporate cannot be accessed from within a ListItemComponent.

    You have to give the access in another way:

    • Access with : groupListItem.ListItem.view.getCorporate();
    • Define a javascript function inside the listView: function getCorporate(){return _corporate;}