I am Learning QML newly and am trying to resolve the following warning: [warning] main.qml:392:25: Unable to assign [undefined] to double
main.qml
Rectangle{
id: rect
...
readonly property real scale0: (rotateRepeater.yPointM - rotateRepeater.yPointT) / height
readonly property real scale1: (rotateRepeater.yPointB - rotateRepeater.yPointM) / height
readonly property real yScale: [scale0, scale1][index] // Warning is in this line
}
The error is being show for property yScale.
Method 1 that I tried was -
readonly property real yScale: Binding {
when: onScale0Changed && onScale1Changed
yScale: [scale0, scale1][index]
}
and got the following error : "cannot assign to non-existent property "yScale"
I tried Googling and found out two possible answers -https://stackoverflow.com/questions/52290153/qml-unable-to-assign-undefined-to -https://stackoverflow.com/questions/73306793/qml-failure-accessing-properties-with-error-unable-to-assign-undefined-to
but, I was unable to solve the warning. Any help here is much appreciated.
Thanks in Advance.
CodePudding user response:
I'm not certain, but I believe you are trying to create an array of the two scale values and then assign one of them to yScale depending on what index
is set to. You should have explained that yourself in your question, especially when directly asked by @Aamir in the comments.
Does it work if you separate out the declaration of the array from its indexing?
readonly property var scaleArray: [scale0, scale1]
readonly property real yScale: scaleArray[index]
CodePudding user response:
As I said above, you probably set incorrect index that is out of range. Check this code:
Item {
id: item
property int index: 0
property double value: [1.0, 2.0, 3.0][index]
onValueChanged: {
console.log(value)
}
Timer {
interval: 1000;
running: true;
repeat: true
onTriggered: item.index = Math.round(Math.random() * 3)
}
}
The output is possible will be:
qml: 1
qml: 3
qml: 2
main.qml:18:9: Unable to assign [undefined] to double
qml: 3
qml: 2
qml: 3
main.qml:18:9: Unable to assign [undefined] to double