• 3940阅读
  • 1回复

如何模拟向GUI发送按键事件 [复制链接]

上一主题 下一主题
离线twodiamond
 

只看楼主 倒序阅读 楼主  发表于: 2016-03-04
— 本帖被 XChinux 执行加亮操作(2016-03-07) —
请教:
        希望模拟向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


        该如何实现这个目的呢?


谢谢!
离线dbzhang800

只看该作者 1楼 发表于: 2016-03-07
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.
快速回复
限100 字节
 
上一个 下一个