Welcome!

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

Reply
Contributor
JUhrig
Posts: 31
Registered: ‎09-25-2012
My Device: N/A
My Carrier: Rogers
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

List.qml

 

Page

{

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

}//EndPage

 

WorkoutListItem.qml

 

Container {
id:root
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
}
}
}

 

application.cpp

 

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

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

 

 

 

Thank you in advance for any help :smileyhappy:

-J

Please use plain text.
Developer
ekke
Posts: 1,413
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

itemRoot.ListItem.view.yourFunction(ListItemData)

 yourFunction(data) is defined in ListView itself

from there you have access to your context

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

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

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.
Contributor
JUhrig
Posts: 31
Registered: ‎09-25-2012
My Device: N/A
My Carrier: Rogers

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.

Please use plain text.