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 reader with unicode chars
Forum Updated to NodeBB v4.3 + New Features

barcode reader with unicode chars

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 4 Posters 2.4k 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.
  • G Offline
    G Offline
    gregorf
    wrote on last edited by
    #7

    Trying to continue on the task. I implemented a key event filter and there is a difference between the unicode char read by barcode scanner and unicode char entered via keyboard ALT+5320.

    Barcode scanner (first line on pic):

    QKeyEvent(KeyPress, Key_Alt, AltModifier)
    QKeyEvent(KeyPress, Key_Alt, AltModifier)
    QKeyEvent(KeyPress, Key_Alt, AltModifier)
    QKeyEvent(KeyPress, Key_Plus, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_Plus, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_Plus, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_5, AltModifier, text="5")
    QKeyEvent(KeyPress, Key_5, AltModifier, text="5")
    QKeyEvent(KeyPress, Key_3, AltModifier, text="3")
    QKeyEvent(KeyPress, Key_3, AltModifier, text="3")
    QKeyEvent(KeyPress, Key_2, AltModifier, text="2")
    QKeyEvent(KeyPress, Key_2, AltModifier, text="2")
    QKeyEvent(KeyPress, Key_0, AltModifier, text="0")
    QKeyEvent(KeyPress, Key_0, AltModifier, text="0")
    QKeyEvent(KeyPress, 0, text="?")
    QKeyEvent(KeyPress, 0, text="?")
    

    Keyboard (second line on pic):

    QKeyEvent(KeyPress, Key_Alt, AltModifier)
    QKeyEvent(KeyPress, Key_Alt, AltModifier)
    QKeyEvent(KeyPress, Key_Alt, AltModifier)
    QKeyEvent(KeyPress, Key_Plus, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_Plus, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_Plus, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_5, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_5, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_5, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_3, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_3, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_3, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_2, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_2, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_2, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_0, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_0, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, Key_0, AltModifier|KeypadModifier)
    QKeyEvent(KeyPress, 0, text="?")
    QKeyEvent(KeyPress, 0, text="?")
    

    d84a2435-f0c4-4d16-ba56-50deed91d058-image.png

    Diff is in AltModifier|KeypadModifier vs AltModifier|text and I get unicode hex in text with actual char in QT app. Now trying to check if scanner has some useful settings to play with. Still interesting that notepad and other applications handle this properly.

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #8

      Hi, think this might be a bug in Qt, if you read on Wikipedia you have to enter a registry key EnableHexNumpad in HKCU\Control Panel\Input Method (at least on my english-only Windows 10 PC I had to do it) to be able to enter Unicode characters.

      To enter Unicode chars, first you begin by typing Alt and the + key on the numeric keypad. Once you've done that, you can either use the digits on the numeric keypad or you can use the normal digits above the letters. (This is in contrast to the ancient way of entering ascii chars using the Alt-Key, then only the digits on numeric keypad were allowed.)

      So your keyboard scanner is correctly set, and Qt needs to adhere to this standard of entering Unicode char.

      1 Reply Last reply
      2
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #9

        I can add characters the way described in the wikipedia article in a QLineEdit.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2
        • G Offline
          G Offline
          gregorf
          wrote on last edited by
          #10

          Yes, I have EnableHexNumpad set in the registry and can enter ALT+hex. As tested in QTextEdit, QPlainTextEdit and QLineEdit I'm getting proper characters. Anyway barcode reader behavior is the same in every tested QT edit controls although key sequence seems similar to manual entry via keyboard.

          1 Reply Last reply
          0
          • hskoglundH Offline
            hskoglundH Offline
            hskoglund
            wrote on last edited by
            #11

            This bug in Qt is easy to reproduce on any Windows 10 PC:
            first enable the Unicode input method described in Wikipedia.

            Then create a vanilla Qt Widget app with a single edit control.

            If you enter Unicode chars starting with the numpad + key and then only use the digits on the numeric keypad, Qt's edit control behaves fine just like Notepad.

            But if you enter Unicode chars starting with the numpad + key and then use the digit keys above the letters on the keyboard, Notepad will handle that with no side effects but Qt will not :-(

            By pure accident/chance your barcode scanner is set to use input method #2 and not input method #1, but both should really work the same (as Notepad shows).

            1 Reply Last reply
            3
            • G Offline
              G Offline
              gregorf
              wrote on last edited by
              #12

              Great point, thank you. Checking key event sequence confirms your findings that scanner uses method #2. Will review the scanner settings for additional options. Hopefully there is something to override the Qt behavior.

              1 Reply Last reply
              0
              • hskoglundH Offline
                hskoglundH Offline
                hskoglund
                wrote on last edited by
                #13

                If you don't find any way to change the scanner's behavior, as a workaround for Qt you could try fixing it yourself.

                That would mean adding an event handler to your Qt program that checks for keyboard events with ALT+numeric key (but without the KeypadModifier), then removing that key event and instead inserting a new keyboard event with the same ALT+numeric key and with KeypadModifier added to it. I.e. your Qt program would simulate that the scanner uses input method #1:-)

                1 Reply Last reply
                3
                • hskoglundH Offline
                  hskoglundH Offline
                  hskoglund
                  wrote on last edited by
                  #14

                  Hi, had a walk this morning when I realized your scanner has no choice but to use input method #2.

                  Remember that name for the registry entry, EnableHexNumpad? It's called ...hex.. for a reason, i.e. sometimes you also need to use the letters A-F for entering Unicode characters, and those are not available on the numeric keypad (so they will always display as junk in a Qt program).

                  Just created a Qt bug entry where I used the Unicode Leftwards Arrow U+2190 as the first example, and then Unicode Leftwards White Arrow U+21E6 as an example where you cannot avoid getting junk characters in your Qt program.

                  Christian EhrlicherC 1 Reply Last reply
                  6
                  • G Offline
                    G Offline
                    gregorf
                    wrote on last edited by
                    #15

                    Hi, thank you for thinking on the matter and for reporting the bug. Yes, method #1 is missing the hex letters. Anyway I did try some scanner settings as there are different keyboard emulations supported, just no real effect as expected.

                    Entering ALT+21E6 also stops my demo Qt app as E is detected in the sequence :-). ALT+21D6 is ok .. could probably override that ALT+E, just notepad or other apps do nothing during unicode sequence besides char conversion at the end.

                    I'll keep the manual event handling on the hold for now. I'm planning to check the option where scanner sends actual hex codes with prefix/suffix and i'll try to switch them into actual char manually. Also need to review the scanner and Qt behavior on Linux. Will post some findings.

                    1 Reply Last reply
                    0
                    • hskoglundH hskoglund

                      Hi, had a walk this morning when I realized your scanner has no choice but to use input method #2.

                      Remember that name for the registry entry, EnableHexNumpad? It's called ...hex.. for a reason, i.e. sometimes you also need to use the letters A-F for entering Unicode characters, and those are not available on the numeric keypad (so they will always display as junk in a Qt program).

                      Just created a Qt bug entry where I used the Unicode Leftwards Arrow U+2190 as the first example, and then Unicode Leftwards White Arrow U+21E6 as an example where you cannot avoid getting junk characters in your Qt program.

                      Christian EhrlicherC Online
                      Christian EhrlicherC Online
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #16

                      @hskoglund But Qt Quick and Widgets team? It's a core input problem and has nothing to do with widgets :)

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      hskoglundH 1 Reply Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        @hskoglund But Qt Quick and Widgets team? It's a core input problem and has nothing to do with widgets :)

                        hskoglundH Offline
                        hskoglundH Offline
                        hskoglund
                        wrote on last edited by hskoglund
                        #17

                        @Christian-Ehrlicher Sorry my bad :-(
                        Indeed in this case the widgets are innocent for once.
                        P.S. Changed the title of the bug entry to avoid blaming the widgets.

                        BTW, do you know anything about that new widget on/off switch that was promised I think late 2018?

                        Christian EhrlicherC 1 Reply Last reply
                        0
                        • hskoglundH hskoglund

                          @Christian-Ehrlicher Sorry my bad :-(
                          Indeed in this case the widgets are innocent for once.
                          P.S. Changed the title of the bug entry to avoid blaming the widgets.

                          BTW, do you know anything about that new widget on/off switch that was promised I think late 2018?

                          Christian EhrlicherC Online
                          Christian EhrlicherC Online
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #18

                          @hskoglund said in barcode reader with unicode chars:

                          that new widget on/off switch

                          Never heard of, any references?

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          hskoglundH 1 Reply Last reply
                          0
                          • Christian EhrlicherC Christian Ehrlicher

                            @hskoglund said in barcode reader with unicode chars:

                            that new widget on/off switch

                            Never heard of, any references?

                            hskoglundH Offline
                            hskoglundH Offline
                            hskoglund
                            wrote on last edited by
                            #19

                            @Christian-Ehrlicher https://www.qt.io/blog/2019/02/22/qt-roadmap-2019 search for "switch"
                            Granted, there is one in QML https://doc.qt.io/qt-5/qml-qtquick-controls2-switch.html but I really like to work with widgets (I even use them in my iPhone Qt app)

                            1 Reply Last reply
                            1
                            • G Offline
                              G Offline
                              gregorf
                              wrote on last edited by
                              #20

                              Hi, I'm playing with the key press event filters to manually convert the hex code and found some more details for the hexcode + char display combination (method #2) which might be useful for the fix.

                              Keypress event comes from several objects and somehow Alt+ combination seems to work for one of them while the second displays the hex code:

                              QKeyEvent(KeyPress, Key_Alt, AltModifier) QWidgetWindow(0x1f4300f0, name = "WidgetClassWindow")
                              QKeyEvent(KeyPress, Key_Alt, AltModifier) QTextEdit(0x1f416a50)
                              QKeyEvent(KeyPress, Key_Plus, AltModifier|KeypadModifier) QWidgetWindow(0x1f4300f0, name = "WidgetClassWindow")
                              QKeyEvent(KeyPress, Key_Plus, AltModifier|KeypadModifier) QTextEdit(0x1f416a50)
                              QKeyEvent(KeyPress, Key_5, AltModifier, text="5") QWidgetWindow(0x1f4300f0, name = "WidgetClassWindow")
                              QKeyEvent(KeyPress, Key_5, AltModifier, text="5") QTextEdit(0x1f416a50)
                              QKeyEvent(KeyPress, Key_3, AltModifier, text="3") QWidgetWindow(0x1f4300f0, name = "WidgetClassWindow")
                              QKeyEvent(KeyPress, Key_3, AltModifier, text="3") QTextEdit(0x1f416a50)
                              QKeyEvent(KeyPress, Key_2, AltModifier, text="2") QWidgetWindow(0x1f4300f0, name = "WidgetClassWindow")
                              QKeyEvent(KeyPress, Key_2, AltModifier, text="2") QTextEdit(0x1f416a50)
                              QKeyEvent(KeyPress, Key_0, AltModifier, text="0") QWidgetWindow(0x1f4300f0, name = "WidgetClassWindow")
                              QKeyEvent(KeyPress, Key_0, AltModifier, text="0") QTextEdit(0x1f416a50)
                              QKeyEvent(KeyPress, 0, text="?") QWidgetWindow(0x1f4300f0, name = "WidgetClassWindow")
                              QKeyEvent(KeyPress, 0, text="?") QTextEdit(0x1f416a50)
                              

                              Catching the ALT, + and 0-F keys for one of the objects (QTextEdit or QWidgetWindow) and not forwarding them further, actually makes the application work and result is only the real character displayed.

                              Final result where mentioned key events for QTextEdit are filtered out:

                              QKeyEvent(KeyPress, Key_Alt, AltModifier) QWidgetWindow(0x1d5f0510, name = "WidgetClassWindow")
                              QKeyEvent(KeyPress, Key_Plus, AltModifier|KeypadModifier) QWidgetWindow(0x1d5f0510, name = "WidgetClassWindow")
                              QKeyEvent(KeyPress, Key_5, AltModifier, text="5") QWidgetWindow(0x1d5f0510, name = "WidgetClassWindow")
                              QKeyEvent(KeyPress, Key_3, AltModifier, text="3") QWidgetWindow(0x1d5f0510, name = "WidgetClassWindow")
                              QKeyEvent(KeyPress, Key_2, AltModifier, text="2") QWidgetWindow(0x1d5f0510, name = "WidgetClassWindow")
                              QKeyEvent(KeyPress, Key_0, AltModifier, text="0") QWidgetWindow(0x1d5f0510, name = "WidgetClassWindow")
                              QKeyEvent(KeyPress, 0, text="?") QWidgetWindow(0x1d5f0510, name = "WidgetClassWindow")
                              
                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                gregorf
                                wrote on last edited by
                                #21

                                Just small update on using barcode scanner on Linux. Unicode entry via keyboard on full Linux is possible on following ways:

                                • Hold SHIFT + CONTROL + u + hex code, release and char will appear - hex entered via numeric keypad, hex A-F via regular keypad {e.g. SHIFT + CONTROL + u + 5320 or SHIFT + CONTROL + u + 30B7}.
                                • Hold SHIFT + CONTROL and press u, release keys, type hex (unicode char), press enter and char will appear - hex entered via regular keypad {e.g. SHIFT + CONTROL + u, release, then 5320, then enter}.

                                As we are using embedded Linux solution with EGLFS mode, none of this unicode entry works with the Qt. Also ALT+hex combination from windows does not work. Besides that, barcode scanner does not support SHIFT + CONTROL + u Linux mode.

                                To overcome this, I played with key press event filter to catch keys ALT, + and the following hex code. And when ALT gets released, I just convert the caught code to the actual char with the following code.

                                bool ok = false;
                                QString g = QChar(arg.toInt(&ok, 16)); // conversion of the hex sequence to the actual char
                                

                                Works really well, just need to do some more tests.

                                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