QCoreApplication::sendEvent does not work with QML
-
I use QCoreApplication::sendEvent (QObject * receiver, QEvent * event) to send KeyEvent to QML TextInput.
For sone reason TextInput does not catch the event.
Anyone know why ? -
Hello,
could you post some code please ? -
@
QKeyEvent keyEvent(_type,
m_unicode,
m_modifiers,
QString(m_unicode),
_autoRepeat);
QApplication::sendEvent(_textInputPtr, &keyEvent);
@ -
Well, how did you get a pointer _textInputPtr on your QML element ?
How did you connect with the Context or with DecalrativeView?please post the complete code....
-
textInputPtr is the id of the TextInput from the QML.
I made a c++ item which inherits QWidget and used on QML (i registered it)
-
You cannot use QML id in C++, that don't make any sense.
May i ask you what kind of thing you want to achieve with your textInput?
In some case, it is quite simplier to manage things in javascript inside QML, and then send an signal to C++ when needed. -
The qML id is a pointer to QObject.
I want to use a c++ virtual keyboard on QML -
How about sending a mouse event? e.g. https://gist.github.com/4415306
-
But I want to send Key event
-
At least with Qt5, one working solution seemingly is to use receiver->window()->sendEvent(),
as depicted at https://bugreports.qt-project.org/browse/QTBUG-15496 . -
@mlvljr
receiver->window()->sendEvent()
deprecated since 5.8. What to use instead?!BTW, it does not work as well.
-
@aabc Have you tried this?
QKeyEvent *event = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); QCoreApplication::postEvent (engine->rootObjects().first(), event);
-
@KroMignon said in QCoreApplication::sendEvent does not work with QML:
@aabc Have you tried this?
QKeyEvent *event = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); QCoreApplication::postEvent (engine->rootObjects().first(), event);
But where is the
receiver
here?