qmlbook / qt6book

The Qt 6 Book - A book about QML
https://www.qt.io/product/qt6/qml-book
Other
342 stars 112 forks source link

Button: Cannot assign to non-existent property "onTriggered" #147

Closed Honghe closed 2 years ago

Honghe commented 2 years ago

Env:

Use the qml following https://github.com/qmlbook/qt6book/blob/75d3677770/docs/ch15-javascript/javascript.md

import QtQuick
import QtQuick.Controls

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    Rectangle {
        Button {
          width: 200
          height: 300
//          property bool checked: false
          text: "Click to toggle"

          // JS function
          function doToggle() {
            checked = !checked
          }

          onTriggered: {
            // this is also JavaScript
            doToggle();
            console.log('checked: ' + checked)
          }
        }
    }
}

But compiled with error output:

QQmlApplicationEngine failed to load component
qrc:/demo_qml_c/main.qml:22:11: Cannot assign to non-existent property "onTriggered"