qmlqkeyevent

Can't access some supposedly public properties on the QKeyEvent object


There is a list of public properties here: http://doc.qt.io/qt-5/qkeyevent.html

I try to access them:

            Keys.onPressed: {
                console.log("matches: ", event.matches("="));
                console.log("text: ", event.text());
                console.log("native modifiers: ", event.nativeModifiers());
                console.log("native scan code: ", event.nativeScanCode());
                console.log("native virtual key: ", event.nativeVirtualKey());
            }

I can access the matches property, but not the others.

24.317 D: onPressed: matches:  false
24.317 W: unknown: ...: TypeError: Property 'text' of object QQuickKeyEvent(0x10e6cad90) is not a function

Why?


Solution

  • Because you are access a property as a function call.

    Just use event.text instead.