Parameter "event" is not declared.
-
This piece of code is of https://www.qt.io/product/qt6/qml-book/ch04-qmlstart-input#keys-element:
import QtQuick import QtQuick.Controls Window { width: 640 height: 480 visible: true title: qsTr("Hello World") Rectangle { id: square width: 100; height: 100 anchors.centerIn: parent color: "green" focus: true Keys.onLeftPressed: square.x -= 8 Keys.onRightPressed: square.x += 8 Keys.onUpPressed: square.y -= 8 Keys.onDownPressed: square.y += 8 Keys.onPressed: { switch(event.key) { case Qt.Key_Plus: square.scale += 0.2 break; case Qt.Key_Minus: square.scale -= 0.2 break; } } } /* Dialog { id: dialog title: "Title" standardButtons: Dialog.Ok | Dialog.Cancel visible: true modal: true } */ }
But I get the error: Parameter "event" is not declared.
Why, please? -
Looks like a bug in the book, it's using Qt5 syntax. Here is the correct and ugly one for Qt 6:
Keys.onPressed: (event)=> {
-
Looks like a bug in the book, it's using Qt5 syntax. Here is the correct and ugly one for Qt 6:
Keys.onPressed: (event)=> {
-
It's all in the documentation, please look it up. https://doc.qt.io/qt-5/qml-qtquick-keys.html