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. KeyStrokes: Parameter "event" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.
Forum Updated to NodeBB v4.3 + New Features

KeyStrokes: Parameter "event" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 4 Posters 1.4k Views
  • 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.
  • S Offline
    S Offline
    shokarta
    wrote on last edited by
    #1

    Hello...

    in Qt5 I have used:

    Rectangle {
        id: parentObject
        anchors.fill: parent
        focus: true
        Keys.onPressed: {
            console.log(event.key + " // " + event.text)
        }
    }
    

    which now in Qt6 gives me error:

    Parameter "event" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.
    

    How this shall be done correctly?

    JonBJ 1 Reply Last reply
    0
    • S shokarta

      Hello...

      in Qt5 I have used:

      Rectangle {
          id: parentObject
          anchors.fill: parent
          focus: true
          Keys.onPressed: {
              console.log(event.key + " // " + event.text)
          }
      }
      

      which now in Qt6 gives me error:

      Parameter "event" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.
      

      How this shall be done correctly?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @shokarta
      https://forum.qt.io/topic/134278/parameter-event-is-not-declared says:
      Keys.onPressed: (event)=> {

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shokarta
        wrote on last edited by
        #3

        yea i tried that before, but this does not work at all:

        Rectangle {
            id: parentObject
            anchors.fill: parent
            focus: true
            Keys.onPressed: {
                event => {
                    console.log(event.key + " /// " + event.text)
                }
            }
        }
        
        jsulmJ JonBJ 2 Replies Last reply
        0
        • S shokarta

          yea i tried that before, but this does not work at all:

          Rectangle {
              id: parentObject
              anchors.fill: parent
              focus: true
              Keys.onPressed: {
                  event => {
                      console.log(event.key + " /// " + event.text)
                  }
              }
          }
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @shokarta said in KeyStrokes: Parameter "event" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.:

          Keys.onPressed: {
          event => {
          console.log(event.key + " /// " + event.text)
          }
          }

          This is not what was suggested

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            shokarta
            wrote on last edited by shokarta
            #5

            thank you,

            this works perfect:
            ```
            Keys.onPressed: event => {
            console.log(event.key + " /// " + event.text)
            //event.accepted = true
            }

            jsulmJ 1 Reply Last reply
            0
            • GrecKoG Offline
              GrecKoG Offline
              GrecKo
              Qt Champions 2018
              wrote on last edited by
              #6
              Keys.onPressed: event => {
                  console.log(event.key + " /// " + event.text)
              }
              
              1 Reply Last reply
              0
              • S shokarta

                thank you,

                this works perfect:
                ```
                Keys.onPressed: event => {
                console.log(event.key + " /// " + event.text)
                //event.accepted = true
                }

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @shokarta I guess

                Keys.onPressed: (event) => {
                            console.log(event.key + " /// " + event.text)
                }
                

                ?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • S shokarta

                  yea i tried that before, but this does not work at all:

                  Rectangle {
                      id: parentObject
                      anchors.fill: parent
                      focus: true
                      Keys.onPressed: {
                          event => {
                              console.log(event.key + " /// " + event.text)
                          }
                      }
                  }
                  
                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @shokarta said in KeyStrokes: Parameter "event" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.:

                  yea i tried that before, but this does not work at all

                  But what you chose to type is not what I wrote or quoted from, the idea is to copy what works not change it.

                  1 Reply Last reply
                  0
                  • fcarneyF fcarney referenced this topic on

                  • Login

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