Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Detect if delegate item inside ListView has been destroyed

$
0
0
Hi, I have a special problem, kinda :D I have a ListView with item delegates like usual, but my ListView model contains only partial data and for every delegate item extra data is being dynamically loaded when the delegate is completed. short example: ListView {   ...   delegate: Item {     ...     Text { id: textItem }     Component.onCompleted: webservice.loadDataAsync(function(data) {       textItem.text = data.text // this may crash the app     })   } } so I have a web service in C++ and call the slot loadDataAsync with a JavaScript closure as a callback, that works fine the problem is just if you scroll around in the ListView and the callback gets called after the delegate has been destroyed by the QML/JS engine the app will crash. That might happen if you scroll fast or the web service is slow obviously, so if the callback is called after the delegate has been destroyed the items in the delegate doesn’t exist anymore and the QMl engine crashed because it can’t fine the item id… so my question is can I somehow check if the delegate has been destroyed in the callback function or does anyone have a better solution maybe? thanks. from C++ I check if the callback is valid and callable, but I don’t think I can access the delegate or anything more from there, the callback is simply of type QJSValue. btw I like that you can do crazy JavaScript/C++ interaction like this lol

Viewing all articles
Browse latest Browse all 4972

Trending Articles