reading barcode from barcode scanner
-
Hi and welcome
Normally if a scanner acts like a keyboard - the way to read it, is to have
a edit control focused so all input goes there.
It simply sends the barcode data as it was typed on keyboard.
This is on Desktop though.
Could be different on android.Should be easy to test. Just take any program that accept text input and
press scan. -
Hi mrjj,
thanks. Yes, I have created a dummy application. It's just a dummy Windows Dialog. and I have a create a QTextEdit. It seems works if i touch/select QTextEdit box on the application. When I pressed button on the tablet, the MainWindow::KeyPressEvent print out the correct information.
The problem i have is I don't want to press on the screen and select the QTextEdit widget, is there anyway to connect m_barcode as the default input for the 'keyboard'?
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); m_barcode = new QTextEdit(ui->centralWidget); qDebug()<< "Setting up focus"; qApp->setActiveWindow(m_barcode); m_barcode->setFocusPolicy(Qt::StrongFocus); m_barcode->setFocus(); m_barcode->setContextMenuPolicy(Qt::DefaultContextMenu); setFocus(); // grabKeyboard(); } void MainWindow::keyPressEvent(QKeyEvent *event){ qDebug() <<"key:" << m_barcode->toPlainText(); }
Thanks.
-
Hi
The "keyboard" goes to the widget that has focus.
Setting focus should do it
m_barcode->setFocus();but remove the
setFocus(); << set focus to main window..You can check if it is as expected - if you can start app and just type and it shows it.
Else something else stole the focus :) -
cool. thanks. it works on my desktop where i can type properly. I guess it doesn't work on the android. I do have the sdk from the manufacturer. probably will use the sdk instead of using their build-in barcode scanner application. but the sdk is using Java.
thank btw :) I'll close off this topic anyway and will create a separate for the question on the loading sdk on the qt project.
-
Hi mrjii,
Thanks for the tips. Still not quite working. although at it startup, the cursor is shows on the m_barcode textbox. The m_barcode will only pick up the 'keyboard input' from the barcode scanner when the keyboard pop-up on the screen.
I'm looking is the application doesn't shows the keyboard on the screen but automatically read from the barcode scanner when i pressed on the button next to the tablet. I guess using their sdk is my last resort.
thanks for all the great tips btw. :)
-
Good testing :)
Ok, seems that focus is not enough. If cursor is show in edit then it should have the focus.
Guess it checks for keyboard open or something like that.So if you want this to work without keyboard being shown then
yes, the SDK might help. -
Hi,
How can i use the barcode reader to read the barcode and display in a textbox in GUI?
What is the code to trigger a event and handle the event to display barcode?
Please provide me the code for this!
Thanks & Regards,
Kripashree -
@kripashree said in reading barcode from barcode scanner:
Please provide me the code for this!
This is a forum where people help as volunteers.
You first need to clarify how you can access your barcode reader, this is not related to Qt.
What device is you barcode reader?
On which OS do you want to access it?
On which device?
How is your barcode scanner connected to your machine?
Can you already access your barcode scanner? -
Hi,
I am going to use hand held scanner in linux machine using usb interface.
Thanks & Regards,
Kripashree -
Some years ago I implemented Barcode Scanner for BlackBerry 10 using Bluetooth SPP.
Now my customers switched to Android / iOS and I was looking HowTo implement Barcode Scanners.
BT SPP only works on Android, but not on iOS
Using Barcode Scanners as Keyboard you must be in a TextField. I tried to immediately hide the virtual keyboard - works, but there's a short flicker when Keyboard comes up and went away
Some Barcode Scanners have a special SDK - in most cases only for for AndroidThen I found out that some vendors of Barcode Scanners (per ex. GeneralScan) also provide a BT LE API.
That's cool because BT LE works on Android and iOS
There's no default GATT profile for Barcode Scanners using BT LE, so you must know the custom Service UUID and Characteristic UUID
I added this for GeneralScan to my Qt BT LE Example App at github (https://github.com/ekke/ekkesBTLEexample)
As soon as Qt 5.12.1 is out I'll also update the Apps at Google Play Store and Apple App StoreOver all it works great:
- connect to the BT LE Device
- look for the Custom Service UUID
- subscribe to NOTIFY Characteristic
Now you can listen to the Barcodes read from Barcode Scanner via BT LE without the need to have focus at Textfield.
I'm just implementing this into three Customer Apps on Android / iOS
When this is finished I'll create another Example at Github to scan EAN13 Barcodes and lookup for the product from web, so you have a kind of real-life-app-experienceNext step is to connect a mobile (Barcode) Printer via BT LE.
It's the same as for Barcode Scanner: no default GATT profile, but some vendors provide a BT LE API.
will implement Barcode printing for REGO and ZEBRA printers
will take some weeks, then I'll add to my BT LE example App and also create another example app to print a specific Barcode to rename a GeneralScan Barcode Scanner. My customer needs such a printer to make it easy to manage the Scanner Names to distinguish them. (In the morning there are 20 employees connecting their Android Phone to Barcode Scanner)Most difficult part to implement BT LE Barcode Scanners / Mobile Printers was to get the infos about the custom Service UUIDs and Characteristic UUIDs and How data was sent to / read from BT LE device. Vendors have SDKs for native Android and native iOS, but I don't want to use them because I want to implement all in one x-platform Qt BT LE App with pure C++/QML ;-)