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

假如想象 提交于 2019-11-27 15:40:36

问题


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


回答1:


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



回答2:


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)



来源:https://stackoverflow.com/questions/2035310/how-can-i-simulate-user-interaction-key-press-event-in-qt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!