Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QKeyEvent and child
I'm currently trying to catch events from a bar code reader. The bar code reader works like an USB keyboard (try with evtest under linux and that's ok).
First, I've simply work on a MainWindow and success to catch all keyboard event from the bar code reader.
Then, I've added another window to catch these events : I try with a QInputDialog, QDialog and QMainWindow but without success. It seems that Qt misses some keyvent, not all characters are printed in qlineedit.
QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"), tr("User name:"), QLineEdit::Normal, "test", &ok); if (ok && !text.isEmpty()) qDebug() << Q_FUNC_INFO << text;
qdebug only outputs 9 characters instead of 16.
How to prevent these missed characters ?
What I have understood from your description is that you are able to catch all the keyboard events from from MainWindow. It means that you have class which is inherited from QMainWindow and implemented keyPressEvent(...). If this the case Qt is not missing any event. Not sure what is missing here. If nothing works, we can build our own events based on what is received from BarCode reader and post the events to appropriate objects using the Application::postEvent(..).
What I have understood from your description is that you are able to catch all the keyboard events from from MainWindow. It means that you have class which is inherited from QMainWindow and implemented keyPressEvent(...). If this the case Qt is not missing any event.
You correctly understood.
Now, I would like to add an inputdialog where BarCode reader key events are catched and displayed in a LineEdit (for example). But it appears that not all characters are catched. The missing characters nor appears in keyPressEvent of parent neither in child (qinputdialog).
Could you please advise me on how to proceed step by step to track correctly these events ?
Peer Schneider last edited by
Is it guaranteed that the keyboard events all represent characters which can be displayed? Could it be possible that the keyboard events could represent white spaces or similar things?
Hi @Peer-Schneider ,
Bar code is composed with printable characters (alphanumeric). On the default MainWindow (automatically generated by qtCreator with ui) I catch all characters and then print them in a lineEdit.
Since you are catching all the keyboard events, you can create your own QLineEdit object and post those key events to lineEdit object. This is just work-around to check whether lineEdit catching or displaying those values.
@dheerendra , I'll try as soon as possible. Thanks
Andy314 last edited by
I use a barcode scanner for my app, too. All works without problem for me.
Did you try to input the "key events" in a simple text editor of you OS. Which characters compared to the editor are missing in Qt ?