Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. reading barcode from barcode scanner
Forum Updated to NodeBB v4.3 + New Features

reading barcode from barcode scanner

Scheduled Pinned Locked Moved Solved Mobile and Embedded
androi
13 Posts 6 Posters 9.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • liewjlsL Offline
    liewjlsL Offline
    liewjls
    wrote on last edited by
    #1

    Hi,

    I have an Android tablet and it has a build in barcode scanner. The tablet also has an barcode scanner helper, which i manage to scan (by pressing the button next to the tablet) a barcode and display the barcode on text file or the webpage as a normal string. I'm bit stuck how to my qt application read the barcode when i press the scan button (next to the tablet).

    My dialog has the CDialog::eventFilter(QObject*, QEvent*) does called when i pressed the button next to tablet which it's fine. But I don't know how to retrieve the barcode from the scanner. What i know is the barcode scanner will act as a "keyboard". So how do i read from this "keyboard"? any guide please?

    thanks in advance.

    Regards,
    jenny

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      1
      • liewjlsL Offline
        liewjlsL Offline
        liewjls
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

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

          1 Reply Last reply
          0
          • liewjlsL Offline
            liewjlsL Offline
            liewjls
            wrote on last edited by
            #5

            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.

            mrjjM 1 Reply Last reply
            1
            • liewjlsL liewjls

              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.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @liewjls

              wait, sometime setting focus in constructor is not optimal.

              Last test would be
              void MainWindow::showEvent( QShowEvent* event ) {
              Q MainWindow::showEvent( event );
              m_barcode->setFocus();
              }

              1 Reply Last reply
              1
              • liewjlsL Offline
                liewjlsL Offline
                liewjls
                wrote on last edited by
                #7

                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. :)

                1 Reply Last reply
                2
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  2
                  • K Offline
                    K Offline
                    kripashree
                    wrote on last edited by
                    #9

                    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

                    jsulmJ 1 Reply Last reply
                    0
                    • K kripashree

                      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

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

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

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      2
                      • K Offline
                        K Offline
                        kripashree
                        wrote on last edited by
                        #11

                        Hi,

                        I am going to use hand held scanner in linux machine using usb interface.

                        Thanks & Regards,
                        Kripashree

                        1 Reply Last reply
                        0
                        • ekkescornerE Offline
                          ekkescornerE Offline
                          ekkescorner
                          Qt Champions 2016
                          wrote on last edited by
                          #12

                          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 Android

                          Then 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 Store

                          Over 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-experience

                          Next 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 ;-)

                          ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                          5.15 --> 6.9 https://t1p.de/ekkeChecklist
                          QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                          1 Reply Last reply
                          3
                          • F Offline
                            F Offline
                            fesilghan
                            Banned
                            wrote on last edited by fesilghan
                            #13
                            This post is deleted!
                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved