Atreyu167
Atreyu167

Reputation: 23

I'm trying to send text to an instance of QTermWidget and artificially press enter for the user

I'm using QTermWidget as an embedded terminal within my c++/qt4 project and I'm having trouble emulating a return/enter key press on the terminal. I've spent a few hours on Google looking for anything I could find and through all of the source code for QTermWidget.

I've tried

    QKeyEvent key(QEvent::KeyPress,Qt::Key_Return, Qt::NoModifier);
    QApplication::postEvent(console, &key);

and

    QKeyEvent key(QEvent::KeyPress,Qt::Key_Return, Qt::NoModifier);
    QCoreApplication::postEvent(console, &key);

as well but using QApplication::sendEvent() and QCoreApplication::sendEvent() respectively, with console being the instance of QTermWidget. I am trying to manipulate.

I've also tried

    QKeyEvent key(QKeyEvent::KeyPress, Qt::Key_Return, Qt::NoModifer);

I'm a newbie so please bear with me, and thank you for all your help.

Upvotes: 1

Views: 246

Answers (1)

Atreyu167
Atreyu167

Reputation: 23

I eventually found the answer to this, it is the send an escape sequence to the instance of QTermWidget

QTermWidget::sendText('\r')

Upvotes: 1

Related Questions