开发者

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

开发者 https://www.devze.com 2022-12-16 02:20 出处:网络
I need to simulate \"Enter\" key event in开发者_运维技巧 Qt. How can I do this?The correct answer might be this:

I need to simulate "Enter" key event in开发者_运维技巧 Qt. How can I do this?


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)


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

精彩评论

暂无评论...
验证码 换一张
取 消