I have a qml Window with an Item which has
Keys.onPressed {
}
And I have a c++ class which has
protected:
void keyPressEvent(QKeyEvent *event);
What needs to go inside the Keys.onPressed? I have tried
myclass.keyPressEvent(event)
and I have tried a public Q_INVOKABLE function (handleKeyPress) in my c++ class with parameter (QKeyEvent * event) from which I wanted to call the keyPressEvent.
At runtime the former gives
"TypeError: Property 'keyPressEvent' of object myclass is not a function"
The latter
"Error: Unknown method parameter type: QKeyEvent*".
(I have then found out that qml can only handle pointers to QObject, and QKeyEvent doesn't inherit from QObject but that doesn't help me in finding a solution.)
So what is the correct way to get the keyPressEvent called from qml? Or if this is the wrong approach altogether, what is the correct one if my class needs the information QKeyEvent can give me like which key was pressed etc.?