Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Wrong unicode in QKeyEvent



  • When monitoring the unicode in a QKeyEvent, sometimes the unicode of the key is incorrect. For example, pressing keys in lower case quickly then suddenly an upper letter appears. When checking the unicode, the event->text() shows a upper letter. You have to press the key or multiple keys very quickly in a windows platform. This can be observed through the text of a QLineEdit.


  • Qt Champions 2017

    did you check the QKeyEvent.key() method ? What does it return ?



  • Following is a piece of log snapshot which I printed corresponding info from the QKeyEvent. You can see there is an upper-case K in a group of lower-case input, which I always typed lower-case.

    13:36:50 [50:946] keyPressEvent key:71 text:g unicode:g g
    13:36:50 [50:993] keyPressEvent key:72 text:h unicode:h h
    13:36:51 [51: 42] keyPressEvent key:74 text:j unicode:j j
    13:36:51 [51: 96] keyPressEvent key:75 text:K unicode:K K
    13:36:51 [51:153] keyPressEvent key:76 text:l unicode:l l

    The key() always return the ASC|| code 'A'~'Z' as I know. But in some conditions it return an unexpected character int text() and unicode(). I can reproduce it with a QLineEdit. Just press keyboard randomly and quickly (may press down and move your finger around on the keyboard).



  • Like this, following is a result I copied from the QLineEdit, a 'T' appeared in a group of lower-cases:
    cgtrewdrtgewdsfghjyu67tji76yTjkio76



  • When I used nativeEvent, I couldn't receive WM_SYSKEYDOWN and WM_KEYDOWN, so it was hard to go further on debugging this issue.


Log in to reply