Search code examples
windowsqtqmlmingw32

QML Keys.onReleased fire when pressing key


Env:

Qt 5.13 + Mingw32 + Windows 10 64bit

or

Qt 5.11 + Mingw32 + Windows 10 64bit

Demo code:

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    Item {
        id: name
        anchors.fill: parent
        focus: true
        Keys.onReleased: console.log("onReleased")
    }
}

Problem: QML Keys.onReleased fire when pressing key(Any Key)


Solution

  • From running your example I assume your problem occurs after holding the Key.

    To prevent that you can simply check the isAutoRepeat attribute when you catch the KeyEvent:

    Keys.onReleased: if (!event.isAutoRepeat) console.log("onReleased")