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

前端 未结 2 1595
清酒与你
清酒与你 2020-12-15 17:39

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

2条回答
  •  庸人自扰
    2020-12-15 18:31

    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)

提交回复
热议问题