[SOLVED] QKeyPress - Simulating key press



  • I'm trying to simulate a key press on a lineEdit, but nothing is writing inside the lineEdit..

    I call this slot with a button press :

    locationEdit->setFocus();
    
    QKeyEvent *key_press = new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_A, Qt::NoModifier);
    QApplication::sendEvent(locationEdit, key_press);
    
    QKeyEvent *key_release = new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_A, Qt::NoModifier);
    QApplication::sendEvent(locationEdit, key_release);
    

    Solved with :
    locationEdit->setFocus();
    QTest::keyClick(locationEdit, Qt::Key_A);

    Awesome QTest lib, !


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.