How can I simulate user interaction (key press event) in Qt?

Andersson83 picture Andersson83 · Jan 10, 2010 · Viewed 23.7k times · Source

I need to simulate "Enter" key event in Qt. How can I do this?

Answer

dnlcrl picture dnlcrl · Jan 23, 2012

The correct answer might be this:

QKeyEvent *event = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
QCoreApplication::postEvent (receiver, event);

in fact there are no matching function for call to

QtKeyEvent::QtKeyEvent(Type type, int key)

but there is:

QtKeyEvent::QtKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers)