[Solved] Application crash when updating the text of a label.
-
Dear all,
I'm learning Quick. In a simple application, I try to update the text of a label when a button is pressed. I'm not able to update the text but the application crashes (qt 5.2.2).
How can I fix the problem?
Joaquim Duran
@
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1Rectangle {
id: rootwidth: 800 height: 480 ToolBar { id: toolbar RowLayout { Button { id: writer text: qsTr("Write") onClicked: label1.text = "button pressed" } Button { id: clear text: qsTr("Clear") onClicked: label1.text = "" } Button { id: close text: qsTr("Close") onClicked: Qt.quit(); } Text { id: label1 text: qsTr("text of label") } } }
}
@ -
Hello and welcome to qt-project.org,
first i was very suspicious about your problem, because the QML code should be fine. I've tested it using a QtQuick2AppicationViewer, BUT with Qt 5.1, QtQuick 2.0, QtQuick.Controls 1.0 and QtQuick.Layouts 1.0 and it also worked fine. Could you please provide us all the code you used for running this QML like your Viewer?
-
Onek24,
Thanks for your comment, with it I've found the error in the application. This program is a modification of the default QML application created by Qt Creator. In the default application, a Rectangle is created with a Text and MouseArea elements. When clicking on the Rectangle, the application exits. I didn't remove the MouseArea and Text from the application, but I remove them when posting to the forum.
In fact, the application was not crashing, it was exiting because when clicking with the mouse over the button, the MouseArea was capturing the event but not the button.
Sorry for any inconveniences.
The deleted code:
@
Text {
text: qsTr("Hello World")
anchors.centerIn: parent
}MouseArea { anchors.fill: parent onClicked: { Qt.quit(); } }
@
-
It's allright, im glad that i could help. Please add a [Solved] in front of the topic of this thread, thank you.