Hello

My configuration:
- Debian 10 Buster, Qt 5.11.3 (from distribution packages), X11-based desktop.

I have a problem with Qt (probably with Qt) and I just don't know where to start looking for its culprit. First of all, I decided to make a small program in which I need to insert characters to other applications. Generally, the window is like on-screen keyboard and pressing a button will cause character being sent to currently open application.
The code I have for this action is a known approach, XLib and Xtest to feed re-defined keycodes:

Qt Code:
  1. void MainWindow::push_char(char character)
  2. {
  3. Display * disp; //current X11 display
  4. disp=XOpenDisplay(nullptr); //TODO: fail gracefully when abused in console.
  5. KeySym * xkeysyms = nullptr;
  6. int temporaryKeyCode=0;
  7. int keycodes_start=0;
  8. int keycodes_end=0;
  9. int keysyms_per_keycode=0;
  10. XDisplayKeycodes(disp,&keycodes_start,&keycodes_end); //obtain keycode range for current display.
  11. xkeysyms=XGetKeyboardMapping(disp,keycodes_start,keycodes_end-keycodes_start,&keysyms_per_keycode); //get keysyms start-end
  12.  
  13. for (int i=keycodes_start; i<=keycodes_end; i++) //Iterate through keycode list to obtain free one
  14. {
  15. bool empty_keycode=true;
  16. for (int j=0; j<keysyms_per_keycode; j++) //check all keysyms to be zero
  17. {
  18. int keysym_index = (i - keycodes_start) * keysyms_per_keycode + j; //obtain keysym position
  19. if(xkeysyms[keysym_index] != 0) //if the key is not empty...
  20. {
  21. empty_keycode=false; //nope... next one
  22. break;
  23. }
  24. }
  25. if (empty_keycode) //use this code for our character.
  26. {
  27. temporaryKeyCode=i;
  28. break;
  29. }
  30. }
  31. XFree(xkeysyms); //this finding and freeing must be done every time, not at the program boot-up,
  32. XFlush(disp); //as user may change X settings on the fly, including key tables.
  33. usleep(100*1000); //0.1 delay
  34.  
  35. //Prepare for character send
  36. KeySym sym = XStringToKeysym("U01F92A"); //Uxxxx links unknown UTF char to key even when it's not in any definition. As in xkbcommon-keysyms.h
  37. // KeySym sym = XStringToKeysym("U0142"); //THIS WORKS., the above does not in all applications.
  38.  
  39. if (sym == NoSymbol) //This should rarely happen.
  40. {
  41. sym=XStringToKeysym("x"); //have anything here or throw error.
  42. }
  43.  
  44. KeySym symlist[2]={sym, sym}; //create a keysym list for shifted and unshifted chr
  45. XChangeKeyboardMapping(disp,temporaryKeyCode,2,symlist,1); //assign the list to the mapping
  46. XFlush(disp);
  47. KeyCode code=temporaryKeyCode; //create code out of temporary
  48.  
  49. XTestFakeKeyEvent(disp, code, true, 0); //Press...
  50. XFlush(disp);
  51. usleep(90 * 1000);
  52. XTestFakeKeyEvent(disp, code, false, 0); //Release...
  53. XFlush(disp);
  54.  
  55. symlist[0]=0;
  56. symlist[1]=0;
  57. XChangeKeyboardMapping(disp,temporaryKeyCode,2,symlist,1); //revert the mapping
  58. usleep(90 * 1000);
  59.  
  60. XCloseDisplay(disp); //End routine
  61. return;
  62. }
To copy to clipboard, switch view to plain text mode 

In the code, I have two test lines for making a keysym of UTF character: First one makes it from "U0142", second is "U01F92A" (or U1F92A - an emoji which, at least in my system, shows a smiley).
The routine (currently argument is not processed) works, but not for all characters and not for all applications. Things I observed:
- When characters are like Uxxxx, 2 hex bytes after U, it's OK for all applications I tested: Based on GTK, Qt, Qt Creator itself too, WxWidgets and even an old ?Qt3-based? TDE.
- When characters are longer, like Uxxxxxx - 3 hex bytes after U, it works for GTK, WxWidgets, TDE, but not Qt applications, even not in Qt Creator itself.

This is a strange behavior and for me it looks like there may be some problem with library configuration in my set-up?
When instead of my code I use xdotool (xdotool type "?") I have a similar behavior, that's why I think about misconfiguration.

Thanks in advance.
MW