如何在Qt中模拟用户交互(按键事件)? [英] How can I simulate user interaction (key press event) in Qt?

查看:674
本文介绍了如何在Qt中模拟用户交互(按键事件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Qt中模拟"Enter"键事件.我该怎么办?

I need to simulate "Enter" key event in Qt. How can I do 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)

但是有:

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

这篇关于如何在Qt中模拟用户交互(按键事件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆