Solved Can't a QML file contain more than one QML components?
-
As title, I used qmlscene to interpret a QML file from a QML book, "Qt5 Cadaques", as below. The qmlscene shows that the error at Line of Text component. I tried some other cases, the same thing. How come? The examples come from the Qt book.
Rectangle { // our inlined button ui
id: button
x: 12; y: 12
width: 116; height: 26
color: "lightsteelblue"
border.color: "slategrey"
Text {
anchors.centerIn: parent
text: "Start"
}
MouseArea {
anchors.fill: parent
onClicked: {
status.text = "Button clicked!"
}
}
}
Text { // text changes when button was clicked
id: status
x: 12; y: 76
width: 116; height: 26
text: "waiting ..."
horizontalAlignment: Text.AlignHCenter
} -
Hi @Stan-Huang
due to how QMl is implemented behind the scenes, a QMl-File must always have 1 single root element.your Text Item is a sibling to the Rectangle -> that is not possible
-
@J.Hilk I added another component to contain the two and found it works. Thanks.