Solved Intercept QML keys on C++ side.
-
You can do this with simple timer which fires after 10 minutes. Inside the handler just check whether key event happened. I'm not in favor of event filter in QApplication becz, every event goes there, checks & then responds. It is risky & performance hit.
-
@dheerendra how i can save time of last key event in this case?
-
you can use the following
Window { visible: true width: 640 height: 480 title: qsTr("Hello World") property date startDate :new Date(); property int mils; Timer{ id : tim interval: 10000 repeat: true running: true onTriggered: { var end = new Date(); var elapsed = end.getTime() - startDate.getTime() if (elapsed>=10000){ console.log("Blackout") }else { console.log("No blackout") startDate = new Date() } } } Rectangle{ anchors.fill: parent focus: true objectName: "Dheerendra" Keys.onPressed: { console.log("Key is pressed") startDate = new Date(); } } }
-
@dheerendra i have many places, where key processed. It is hard to put such code everywhere
-
It can be componetized as well. If it is everywhere, catch at the source only with qApp.
-
@dheerendra once again - key events does not appear in filter. Think it is worth to mention that i use linuxfb plugin withOUT libinput.
-
basic question - In your program are you able to catch/handle the keyboard events ?
-
@dheerendra qml ui react to key presses.
-
@egor.utsov said in Intercept QML keys on C++ side.:
if (event->type() == QEvent::Type::KeyPress || event->type() == QEvent::KeyRelease)
Can you just print the event type in eventFilter function ? Right now it is condition based. When you press the keyboard let us see what type events are coming. This may give us hint. If not we will do something else.
-
@dheerendra i am also tried to enable QT_LOGGING_RULES="qt.qpa.input=true", but key events still not printed, however i see beginning of qpa logs
-
while we debug this issue, another option what you can try is Keys.forwardTo option in qml. We can make all the key events forward to one common object. This common object can handle your blackout logic.
what is happening in eventfilter function ? Is it printing the type as key event or not ?
-
@dheerendra Hi. I reboot the unit and now key events appeared in filter. I don't know whats changed, but it works now. Thank you for help and sorry for bothering