Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 31
Registered: ‎09-25-2012
My Device: N/A
Accepted Solution

C++ context reference lost when custome ListItem created in ListView

Hi all,


I have a listview which generates a list of custome listviewItems (ie containers). The containers have a setContextProperty to my database object. But when they are added to the list view I am unable to access the database context property. I realize that the listview doesnt reside in the same context as the page but I do not understand why when I bind the context to the actual item the reference it lost?


Error: asset:///WorkoutListItem.qml:17: ReferenceError: Can't find variable: _Dal





Container {
ListView {
id: workoutList
horizontalAlignment: HorizontalAlignment.Fill

dataModel: _Dal.ListofWorkouts
listItemComponents: [
ListItemComponent {
type: "item"
WorkoutListItem {
workoutId: ListItemData.id
workoutName: ListItemData.name
}//End List
}//End root





Container {
property int workoutId: -1
property variant workoutName: ""

layout: StackLayout {
orientation: LayoutOrientation.LeftToRight

Button {
id: workoutDelete
text: "Delete"
onClicked: {
var result = _Dal.DeleteWorkout(root.workoutId)

Label {
id: workoutNumberLabel
text: root.workoutId

Label {
id: workoutNameLabel
text: root.workoutName

Button {
id: workoutEdit
text: "Edit"
onClicked: {
//TODO: Open workout page




QmlDocument *WorkoutListItem = QmlDocument::create("asset:///WorkoutListItem.qml").parent(this);

WorkoutListItem->setContextProperty("_Dal", dal);




Thank you in advance for any help :smileyhappy:


Posts: 1,625
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: C++ context reference lost when custome ListItem created in ListView


 yourFunction(data) is defined in ListView itself

from there you have access to your context

ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Posts: 31
Registered: ‎09-25-2012
My Device: N/A

Re: C++ context reference lost when custome ListItem created in ListView

Thank you very much this has solved my problem. I guess instead of seperating out the list view item into a seperate qml file i more the whole list view out into a seperate file to clean it up a little.