如何在Qt中模拟用户交互(按键事件)?

时间:2010-01-09 23:04:25

标签: qt qt4 keyevent

我需要在Qt中模拟“输入”键事件。我怎么能这样做?

2 个答案:

答案 0 :(得分:22)

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

答案 1 :(得分:22)

正确答案可能是:

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

实际上没有用于调用

的匹配函数

QtKeyEvent::QtKeyEvent(Type type, int key)

但有:

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