In the AppStudio Sample "Find A Route", I want to extract the text of the Directions, that are in the directionListModel of the l
ListView.
I assume it if fairly simple, and I have tried a buch of things, but I cannot get it - any quick suggestions
e.g., I tried
for(var i = 0; i < directionListModel.count; ++i) {
console.log(directionListModel.get(i).text);
} I get TypeError: Cannot read property 'count' of null I put this at the end of onClicked in the "Solve Route" button
thanks
Solved! Go to Solution.
At the end of onClicked, solveRoute() is being called, but this is an asynchronous task. What you need to do is listen for the tasks status to change. There is already a handler for this not too far below the button in the routeTask object. Put your code into the onSolveRouteTaskStatusChanged block after the directionListModel is filled. At this point, the task will be completed and the data won't be null.
Hope this helps,
Keith
At the end of onClicked, solveRoute() is being called, but this is an asynchronous task. What you need to do is listen for the tasks status to change. There is already a handler for this not too far below the button in the routeTask object. Put your code into the onSolveRouteTaskStatusChanged block after the directionListModel is filled. At this point, the task will be completed and the data won't be null.
Hope this helps,
Keith
As Keith mentioned, it is asynchronous, you need to wait for the results to be ready before you can view it. Try adding the code under the onClicked for the directions button
Another thing is that the property of DirectionManeuver::directionText to get the directions and not just the text
MouseArea {
anchors.fill: parent
onPressed: directionButton.pressed = true
onReleased: directionButton.pressed = false
onClicked: {
// Show the direction window when it is clicked
translate.x = directionWindow.visible ? 0 : (directionWindow.width * -1);
directionWindow.visible = !directionWindow.visible;
for(var i = 0; i < directionListModel.count; ++i) {
console.log(directionListModel.get(i).directionText );
}
}
Nakul
and then there's asynchronous..so the lesson is wait until the data is ready!!
Perfect. That worked - thanks for the quick response
to be specific, I used:
console.log(directionListModel.count); console.log(directionListModel.get(1).directionText) and got
qml: 12
qml: Go east on UPAS ST toward ALBERT ST
fun stuff!