How do I send Key Event from C++ to QML TextInput Item in Qt 5.2 ?
-
How do I send Key Event from C++ to QML TextInput Item in Qt 5.2 ?
-
I'm sure you have QMLViewer object in C++. This is used for launching the QML file. Use this as destination object.
QtQuick2ControlsApplicationViewer w;
You can do
QApplication::postEvent(&w,new QKeyEvent(.....))
-
Can I send it directly to the TextInput ?
-
If this is the focused object, it will be sent to TextInput only.
-
And if its not ?
-
If not we need to look at the issue. There may be other focused elements in the UI. What is the issue you are facing when you do this ?
-
I have pointer to the QML TextInput in C++ and I want to send it a Key event (simulate keyboaed) while it may not be focused
-
if you have pointer to TextInput use the post event as I suggested
QApplication::postEvent(pointerToTextInput,new QKeyEvent(…..))
If you give the sample code it helps us to look/analyze if you have any issue.