Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Parameter "event" is not declared.

Parameter "event" is not declared.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 888 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qcoderpro
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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)=> {
      

      (Z(:^

      Q 1 Reply Last reply
      2
      • sierdzioS sierdzio

        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)=> {
        
        Q Offline
        Q Offline
        qcoderpro
        wrote on last edited by
        #3

        @sierdzio

        Thank you for your nice reply. What is that event there? Will you explain it a little?

        The code runs but the direction (right-left/up-down) keys don't work!

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          It's all in the documentation, please look it up. https://doc.qt.io/qt-5/qml-qtquick-keys.html

          (Z(:^

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved