QML Variant property undefined
Solved
QML and Qt Quick
-
Hi i have a basic QML question might be stupid. I saw in this QML map viewer example, markers is defined as a variant property.
Map { property variant markers
and later directly use like an array
var count = map.markers.length
How the QML knows this is an array? I must have done something wrong, I actually got the following error:
TypeError: Cannot read property 'length' of undefined
-
Hi @ODБOï just like this
var count = map.markers.length
I guess QML does not know it is an array, and I found two ways to solve it
Map { property variant markers: []
or
Component.onCompleted: { markers = new Array(0); }
i'm not sure if this is the right way to do it. I'm still learning QML.