我需要在Qt中模拟“输入”键事件。我怎么能这样做?
答案 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)