无法访问 QKeyEvent 对象上的某些据称 public 的属性

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

此处有 public 个属性列表:http://doc.qt.io/qt-5/qkeyevent.html

我尝试访问它们:

            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());
            }

我可以访问 matches 属性,但不能访问其他的。

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

为什么?

因为您正在访问 属性 作为函数调用。

只需使用 event.text 即可。