[PLEASE HELP] how to make a barcode receiver?
-
@davidlabib To put a string into a line edit this line edit does not need to have focus!
Simply:ui->lineEdit_1->setText(someText);
-
@jsulm I think his problem is at a lower level, not just set the "text" for the proper line edit.
Most barcode reader drivers mimic the keyboard, so when they scan something they place the data read like the keyboard, and SO is facing the issue that if focus is with another widget, not the line edit, if a scan is done that data will go there, or as his last example with the button, lost.
-
@Pablo-J.-Rogina said in [PLEASE HELP] how to make a barcode receiver?:
Most barcode reader drivers mimic the keyboard, so when they scan something they place the data read like the keyboard, and SO is facing the issue that if focus is with another widget, not the line edit, if a scan is done that data will go there, or as his last example with the button, lost.
that's exactly what I'm talking about
You completely understand mebut i don't think that it's a lower level problem
i think that making thread always waiting for input 13 digit --any right barcode in the world contain 13 digit-- less than 1 second
if the input was 13 digit and inputted less than a second then it's a barcode and deal with it as a barcode
else what for input again -
@davidlabib said in [PLEASE HELP] how to make a barcode receiver?:
always waiting for input 13 digit --any right barcode in the world contain 13 digit
Be careful with this assumption, think of EAN 8 for instance...
Like the UPC code, there is the EAN-13 symbology with 13 digits, and an abbreviated EAN barcode called the EAN-8 with only 8 digits for smaller goods where space is limited.
-
@Pablo-J-Rogina thanks for the warning
@mrjj take a look here i think you faced this type of problems
https://forum.qt.io/topic/71310/reading-barcode-from-barcode-scanner -
@davidlabib
Yes, that very normal issues when using a
scanner in HID mode so it acts like a keyboard.I usually put a button next to input that says scan and it popup dialog
to do the scanning in.There is no easy solution to what you try. as unless NOTHING else can have focus. ( you can disable focus for buttons) then user might switch to other edit fields.
Often scanner input is terminated with \n\r or similar- check the documentation
for the scanner. -
@davidlabib I did some grocery shopping yesterday, and looking at the point of sale software the clerk used when I checked out, and also thinking about the shopping cart and checkout process in websites, I wonder why do you need this "always on" scanning phase?
I mean, maybe you're overcomplicating your requirements. Do you really have such use case from an actual user/customer of your application?
While checking out most of the software overthere that I remember have some steps/phases:
- Initial data (optional)
- 1-N items scanning (using barcode reader!!) so focus is there for just one widget (a list where scanned items are added, or a line edit where you click a "Add" button, whatever)
- When you are ready (by self-checkout or a clerk helping you) a "Proceeed to checkout" button move to next phase, i.e. Delivery information or just Payment (at this point if credit card is read, again focus is only for reading the credit card data)
- "Finish" button to print receipt and move into next customer...
Is your use case completely different from this scenario? if so, why!?
-
the only payment method is cash only (for now), so we can skip 3
It's not very require to make focus when the barcode input something but i thought that it will be a good extra feature in the application
-
@davidlabib
Hi
The complication of trying to guess if its user typing or scanner input
can be complicated. While often a scan is terminated with same
symbols, you first know later if scan or keypress and hence
makes it complicated to handle.So its actually complicated to make work flawless and hence a
straight way of saying for user. "I want to scan" is often preferred.
As it avoid confusing and guessing. -
@davidlabib
just a note:
Some barcode scanners have different modes. One mode is "keyboard" mode (like you are using it now) and another can be via the serial interface. The later would let you use QtSerialPort module to receive the scanned code in plain text.
Those modes can be switched by scanning a special barcode. Take a look at the scanners manual. -
@raven-worx
can you help me on setting the right mod and use QtSerialPort -
@davidlabib said in [PLEASE HELP] how to make a barcode receiver?:
can you help me on setting the right mod and use QtSerialPort
If you want to use Qt Serial Port, choose the RS-232 option. You will also need to connect the barcode scanner to a serial port on your computer.
-
@davidlabib
use the very first code (RS232).
Then check the COM port of the scanner it is connected to (e.g. on Windows in the Device Manager).in your .pro file add
QT += serialport
QSerialPort example usage:
QSerialPort* port = new QSerialPort( this ); port->setBaudRate( QSerialPort::Baud115200 ); // possible something else, also check the manual port->setPort( QPortInfo("COM4") ); // COM port - check Device Manager for connected port if( port->open(QSerialPort::ReadOnly) ) { connect(port, &QSerialPort::readyRead, this, [port]() { if( !port->bytesAvailable() ) return; const QByteArray scannedData = port->readAll(); // ... }); } else { // check port->error() }
-
@davidlabib said in [PLEASE HELP] how to make a barcode receiver?:
is it must came from serial port not usb?
Qt Serial Port works with serial ports. A USB port is not a serial port.
If your computer doesn't have a serial port, you can use a USB-to-serial converter.
-
@JKSH said in [PLEASE HELP] how to make a barcode receiver?:
Qt Serial Port works with serial ports. A USB port is not a serial port.
thats not true. Of course QtSerialPort works with USB.
USB = Universal Serial BusThe code above i've posted definitively works with a USB Barcode scanner and i used it myself already.
-
@raven-worx
I'm using ubuntu now -
Hi,
It's QSerialPortInfo.
-
i dosn't do any thing it always execute "else"
QSerialPort::SerialPortError(DeviceNotFoundError)