Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to Run an event (keypressevent) in the background ?
saulad last edited by
I need to be checking the keyboard input for a bar-code-reader (this machine works like a keyboard, typing the code and an "enter" at the end). But I can't keep the parent widget always in front. So, how can I keep the keyPressEvent running?
I found out that QEventLoop may helps, but I don't know how to use it in my constructor. There are not many examples in the Internet.
Thanks for your help.
@class monitor : public QWidget
explicit monitor(QWidget *parent = 0);
void keyPressEvent(QKeyEvent *e);
(You don't create your own event loop in your class. QApplication::exec() creates the event loop in the main() function)
NicuPopescu last edited by
first, the title and the content are misleading somehow as they suggest different things: the title request for a "run" as a code generated key press event and the solution is as JKSH hinted, and the content request for a silent key input checking solution :)
for checking the keyboard input silently I use to grab the keyboard input(by grabKeyboard() method ) to a defined widget(QPushButton or whatever) - by this you avoid to check for any sender , and install an event filter for it to fetch key press events
hope this helps!