View Full Version : Save key input with japanish language (use of QInputMethodEvent)

15th November 2013, 09:19

I have a Qt application and need to save user key input in an array. I mean, what user writes using keyboard (without using any textedit or similar) must be saved in an array.

If I Use
MyClass::eventFilter( QObject *obj, QEvent *event ) method, QEvent::KeyPress' gives me input chars (keyEvent->key()), BUT NOT non-Latin characters, i.e. when japanish language is set.

I have read about QInputMethodEvent Class (http://qt-project.org/doc/qt-5.0/qtgui/qinputmethodevent.html#details), and it seems to be what I need ('...Input methods are widely used to enter text for languages with non-Latin alphabets.'), BUT I do not understand how to use it...

I have tested input panel example (http://qt-project.org/doc/qt-4.8/tools-inputpanel.html), and altough I understand what it does, I do not know how to use this classes for muy purpose.

As far as I know:

I need a Widget (class A) which receives input chars using
void inputMethodEvent( QInputMethodEvent* m ) previous setAttribute( Qt::WA_InputMethodEnabled). But this method is called from a QInputContext. When a QTextEdit is used, a generic QInputContext calls automatically this method and the text is displayed on the edit.
But in my case I have no textEdit, so I suppose I need a class B which inherits QInputContext and sends this event somewhen. But I do not how to do this... If I use '::eventFilter' in class B, I receive char input, BUT when I set japanish, as I said previously.

I am really stuck, so I would appreciate any help.

Thanks in advance,