[PLEASE HELP] how to make a barcode receiver?



  • I'm trying to make a shop manger application and i want to make a barcode receiver .
    when I connect my barcode reader and point to a barcode it inserts the barcode numbers and press enter automatically, so i want to make a Qtextbox always waiting for input even if it wasn't the active widget.


  • Moderators

    @davidlabib said in [PLEASE HELP] how to make a barcode receiver?:

    so i want to make a Qtextbox always waiting for input even if it wasn't the active widget.

    what?



  • @raven-worx as you can see 0_1534104593401_0b2b35dd-052e-4842-a974-5f62cc9291b6-image.png
    the Qlineedit number 1 is the active which mean if i typed something it will be in this field not 2 or 3


  • Moderators

    @davidlabib
    does your barcode scanner really submit a return/enter key press?
    I assume it is rather a \r or \n character at the end?


  • Lifetime Qt Champion

    Hi,

    To add to @raven-worx:

    • What OS are you developing on ?
    • How is your barcode seen by the system ?


  • [EDITED]
    @SGaist Windows 10
    @raven-worx ,Yes the barcode scanner submit return/enter
    i had created a simple form and put in it a QLineEdit, QButton and Qlable
    and created a slot when i press the button it takes the lineedit text and put it in the lable
    also created a shortcut for the button when i return
    0_1534108510217_d417d81b-9d0c-41ff-b3e2-da7a9872773d-image.png
    0_1534108535258_6d93ce0b-b8b3-4737-8830-c443bbe4fee1-image.png
    0_1534108566717_5bb895d7-bd66-4e5f-b5f3-c4644e7e11f8-image.png
    0_1534108666666_232b4413-d0e4-4650-b8a6-c8809e2a097d-image.png
    I'm very sorry about the bad English because it's not my mother language.


  • Lifetime Qt Champion

    So it's basilly seen as a keyboard, correct ?



  • @SGaist edited and yes something like a keyboard


  • Lifetime Qt Champion

    Then you should check with the Windows API if you can target that specific device.



  • @davidlabib said in [PLEASE HELP] how to make a barcode receiver?:

    i want to make a Qtextbox always waiting for input even if it wasn't the active widget

    This is not the original/intended behavior of this widget or any other related widget. The keyboard input is directed to the widget having the focus.

    Given that said:

    1. have you seen any other application working the way you want?
    2. I'd say you may want to override the keyPressEvent() method in MainWindow class and when you "detect a barcode" given the focus is not on it, you paste the value received to it. See this SO question for a related matter.


  • @Pablo-J-Rogina

    1. you almost understand me yes in this quote
    1. I'd say you may want to override the keyPressEvent() method in MainWindow class and when you "detect a barcode" given the focus is not on it, you paste the value received to it. See this SO question for a related matter.
    1. i know that making a Qtextbox always waiting for input is impossible but it was a phrase describe what i want (something like that) i mean

    2. SO question is not what i mean

    what i mean exactly is
    at any time and under any condition when the barcode scanner hardware detetect any barcaode it will do_something()



  • @davidlabib said in [PLEASE HELP] how to make a barcode receiver?:

    at any time and under any condition when the barcode scanner hardware detetect any barcaode it will do_something()

    You've changed the requirements :-)
    In this case I'd say you need to change the barcode driver, and work at a lower level than Qt... so the driver code instead of pasting the decoded text/numbers into the keyboard buffer does some kind of notification that your application can trap. But it looks like that work it's out of scope for Qt framework



  • @Pablo-J-Rogina
    can you send me your number on whatsapp or telegram or any other messenger so we can have a long conversation in private and after we got the solution i will post it in this topic so other can benefits from it



  • @davidlabib please continue this way. I'm not sure I have enough spare time to go on privately. Thanks



  • @Pablo-J-Rogina
    OK ,I'm developing a shop manager application.
    I'm beginner on programing i had learned c++ just for a year or less
    and now I'm learning qt lib.
    i don't have problems with sqlite but have problems with the barcode
    of course i can make a line edit and button when the button got clicked it will search on the database for the barcode and so on
    but the problem is what if I selected another line edit and pointed the barcode scanner hardware to a barcode
    it will type on the anther line edit not the barcode line edit
    so what is your ideas to solve this problem .


  • Moderators

    @Pablo-J.-Rogina said in [PLEASE HELP] how to make a barcode receiver?:

    at any time and under any condition when the barcode scanner hardware detetect any barcaode it will do_something()

    Can't your barcode scanner just write to a string and you then put it in the correct line edit?



  • @jsulm
    yes it write to a string
    but it cannot put this string in the correct line edit
    and what if a button is selected
    0_1534367535920_542f4758-8857-46ef-8892-598bb52a2f78-image.png
    not line edit


  • Moderators

    @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

    @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 me

    but 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


  • Qt Champions 2017

    @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:

    1. Initial data (optional)
    2. 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)
    3. 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)
    4. "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


  • Qt Champions 2017

    @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.


  • Moderators

    @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
    0_1534682994843_f52d64be-c499-4ed8-8c2d-61bd38a1de84-image.png
    0_1534683017626_314576f9-6b75-42fd-b9a7-8124961e7757-image.png
    0_1534683048600_4b9a11df-1307-42af-9058-f90b71a6a88b-image.png
    0_1534683072140_89cd40a7-8a36-49d8-92ab-78edd63f4b99-image.png
    0_1534683090490_c9b50133-170b-49a0-8fea-138ae9c73956-image.png
    0_1534683117128_9f977db8-5b6e-40e8-8f77-80814053f964-image.png
    can you help me on setting the right mod and use QtSerialPort


  • Moderators

    @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.


  • Moderators

    @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()
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.