Wrote a simple QML app, and it's complaining that I can't set the anchors for a text item.
qrc:/main.qml:13 Invalid property assignment: "anchors" is a read-only property
What's going on?
import QtQuick 2.7
import QtQuick.Controls 2.0
ApplicationWindow {
visible: true
width:320; height:240
title: "Driver Confidence"
property real accSpeed: 29.0576
Text {
text: accSpeed.toFixed(0) + " m/s"
anchors: { top:parent.top; left:parent.left }
}
}
The problem is a simple syntax error combined with a confusing error message. The anchors
line should not have a colon after anchors
:
anchors { top:parent.top; left:parent.left }
With the colon it is trying to evaluate the block as a JavaScript expression (which is invalid) and then assign the result to overwrite the entire anchors
object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With