Barcode Scanner - Keyboard vs VirtualCOM
-
@J-Hilk Yes in this way work. But I don't have gui. Only console application.
Moreover I use QML.
maybe it is possible use in QML :
Shortcut { sequence: "Q,E" context: Qt.ApplicationShortcut }
And if my code will be beginning from QE chars then save to all form keyboard to variable, only how to do it ?
-
@J-Hilk Yes in this way work. But I don't have gui. Only console application.
Moreover I use QML.
maybe it is possible use in QML :
Shortcut { sequence: "Q,E" context: Qt.ApplicationShortcut }
And if my code will be beginning from QE chars then save to all form keyboard to variable, only how to do it ?
@Damian7546 I would rather go with an custom event filter and listen for QKeyEvents
you can and should install the event filter on your QCoreApplication that should get all the key events.
-
@J-Hilk How do this ?
-
@J-Hilk How do this ?
@Damian7546 follow the links, they are with example even.
-
I am beginner I do not know how event filter would work with a barcode scanner
-
I am beginner I do not know how event filter would work with a barcode scanner
something like this.
class MyKeyEventFilter : public QObject { Q_OBJECT public: MyKeyEventFilter(QObject *parent = nullptr) : QObject(parent) {} bool eventFilter(QObject *object, QEvent *event) override { Q_UNUSED(object); if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease){ qDebug() << static_cast<QKeyEvent *>(event)->key(); } return false; // <-- Do not swallow the event } };
int main(int argc, char *argv[]) { QApplication app(argc,argv); app.installEventFilter(new MyKeyEventFilter()); QWidget w ; w .show(); return app.exec(); }
not sure if it will work for your hardware.
Only console application.
Moreover I use QML.
this is a contradiction.
I am beginner I do not know how event filter would work with a barcode scanner
thats not an excuse and one has nothing to do with the other. I know even less about your barcode scanner than you do and can only offer suggestions
-
This post is deleted!
-
@ I did like you said with only little change, like below:
bool MyKeyEventFilter::eventFilter(QObject *object, QEvent *event) { Q_UNUSED(object); if(event->type() == QEvent::KeyPress){ if(test.count() >= 12 ) { qDebug() << test; test.clear(); return true; } else { test.append(static_cast<QKeyEvent *>(event)->text()); return false; } } return false; // <-- Do not swallow the event }
Works, but after two times scanned the solution is:
555777---555
222000111---
but it should be
57-57201-N-3
57-57201-N-3
each letter are repeat 3 times, why ?
-
This post is deleted!
-
@J-Hilk
Works great with little filter. Below solution for posterity:bool MyKeyEventFilter::eventFilter(QObject *object, QEvent *event) { Q_UNUSED(object); if(event->type() == QEvent::KeyPress){ if(static_cast<QKeyEvent *>(event)->key() == Qt::Key_Return) { qDebug() << test; test.clear(); return true; } else if (!m_Timeout) { m_Timeout=true; test.append(static_cast<QKeyEvent *>(event)->text()); timDelay.start(1); return false; } else { return false; } } return false; }