https://www.qtcentre.org/threads/153...keyboard-press


I tried the same approach, but not able to get written on the lineEdit widget

Qt Code:
  1. ui->lineEdit->setFocus();
  2. QKeyEvent *key_press = new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_X, Qt::NoModifier);
  3. QApplication::sendEvent(ui->lineEdit, key_press);
To copy to clipboard, switch view to plain text mode 

Alternately

Qt Code:
  1. QApplication::postEvent(ui->lineEdit, key_press);
To copy to clipboard, switch view to plain text mode 
also didn't succeed.

I tried the below also and didn't get any result.

Qt Code:
  1. QKeyEvent key(QEvent::KeyPress, Qt::Key_X, Qt::NoModifier);
  2. QApplication::sendEvent(ui->lineEdit, &key);
  3. if (key.isAccepted()) {
  4. qDebug()<<"everything is ok";
  5. } else {
  6. qDebug()<<"something wrong";
  7. }
To copy to clipboard, switch view to plain text mode 
Please suggest what am I missing.

Regards,
Sayan