Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Barcode Scanner - Keyboard vs VirtualCOM

Barcode Scanner - Keyboard vs VirtualCOM

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 2 Posters 960 Views
  • 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.
  • D Offline
    D Offline
    Damian7546
    wrote on last edited by Damian7546
    #1

    Hi,
    In my Qt application I am using barcode scanner. Until today I use barcode scanner with USB interface working as virtual com port. The application was simple. it opened port and when there was signal readyread then after that i did my logic.
    Now I have barcode scanner with USB interface but working as keyboard.
    How applied this barcodescanner to my applcation ? How emit any signal in my logic when barcode read any code ?

    J.HilkJ 1 Reply Last reply
    0
    • D Damian7546

      Hi,
      In my Qt application I am using barcode scanner. Until today I use barcode scanner with USB interface working as virtual com port. The application was simple. it opened port and when there was signal readyread then after that i did my logic.
      Now I have barcode scanner with USB interface but working as keyboard.
      How applied this barcodescanner to my applcation ? How emit any signal in my logic when barcode read any code ?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Damian7546 have you tried giving a textedit active focus when you try to scan something?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Damian7546
        wrote on last edited by Damian7546
        #3

        @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.HilkJ 1 Reply Last reply
        0
        • D Damian7546

          @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.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

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


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Damian7546
            wrote on last edited by
            #5

            @J-Hilk How do this ?

            J.HilkJ 1 Reply Last reply
            0
            • D Damian7546

              @J-Hilk How do this ?

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @Damian7546 follow the links, they are with example even.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Damian7546
                wrote on last edited by Damian7546
                #7

                I am beginner I do not know how event filter would work with a barcode scanner

                J.HilkJ 1 Reply Last reply
                0
                • D Damian7546

                  I am beginner I do not know how event filter would work with a barcode scanner

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  @Damian7546

                  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


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  1
                  • D Offline
                    D Offline
                    Damian7546
                    wrote on last edited by
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Damian7546
                      wrote on last edited by Damian7546
                      #10

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

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        Damian7546
                        wrote on last edited by
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          Damian7546
                          wrote on last edited by
                          #12

                          @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;
                          }
                          
                          1 Reply Last reply
                          1

                          • Login

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