Hi,

Using this code in a QML program I want to change the text of a button when clicked:

main.qml:
Qt Code:
  1. import QtQuick 2.9
  2. import QtQuick.Window 2.2
  3. import QtQuick.Controls 1.4
  4. import QtQuick.Controls.Styles 1.4
  5.  
  6. Window {
  7. visible: true
  8. width: 720; height: 720
  9. color: "gray"
  10.  
  11. Rectangle {
  12. id: root
  13. x: 10; y: 10
  14. width: 300; height: 300
  15. color: "lightblue"
  16.  
  17. function change() {
  18. st_text.text = "Clicked"
  19. }
  20.  
  21. Button {
  22. id: b1
  23. x: 100; y: 100
  24. style: ButtonStyle {
  25. background: Rectangle {
  26. implicitHeight: 50
  27. implicitWidth: 100
  28. color: "lightGrey"
  29. border.width: 4
  30. border.color: "lightBlue"
  31. radius: 15
  32. Text {
  33. id: st_text
  34. anchors.centerIn: parent
  35. text: "Start"
  36. font.bold: true
  37. font.pixelSize: 15
  38. color: "green"
  39. }
  40. }
  41. }
  42. onClicked: root.change()
  43. }
  44. }
  45. }
To copy to clipboard, switch view to plain text mode 

But when I click the button I get this error:
qrc:/main.qml:18: ReferenceError: st_text is not defined

Why and how to solve that please?