首页| 论坛| 消息

标题:如何模拟向GUI发送按键事件
作者:twodiamond
日期:2016-03-04 17:52
内容:

请教:
希望模拟向GUI发送按键事件:
QKeyEvent keyPress(QEvent::KeyPress, Qt::Key_F1, Qt::NoModifier, QString());
QApplication::postEvent(qApp, &keyPress);
但是不知道此时活动的widget是谁,就直接向QApplication发送,但其运行时错误提示:
QCoreApplication::removePostedEvent: Internal error: 0xe05d908 6 is posted

该如何实现这个目的呢?

谢谢!


#1 [dbzhang800 03-07 16:31]
postEvent()的手册会告诉你错误的原因:

The event must be allocated on the heap since the post event queue will take ownership of the event and delete it once it has been posted.

回复 发表
主题 版块