I know this thread is old, but some of us are still stuck with QT 4.8.4 (QWS) in embedded. I spent some time trying to figure out how to selectAll on a lineEdit that was setup via a UI file.
I tried the following, but it didn't work . ( note it does work when I build for desktop )
ui->lineEdit->selectAll();
ui->lineEdit->setFocus();
Then I noticed If I pressed the line edit then ran the selectAll() it worked.
So if you force a mouse press event for the widget, it forces focus and hence will let you selectALL().
QEvent eventPress( QEvent::MouseButtonPress );
QEvent eventRelease( QEvent::MouseButtonRelease );
QApplication::sendEvent( ui->lineEdit , &eventPress ); // simulate a mouse press
QApplication::sendEvent( ui->lineEdit , &eventRelease ); // simulate a mouse release
ui->lineEdit->selectAll();
This worked for me, I hope it can get someone else out of a bind too.
I'm posting this because I didn't see any other examples of people with this work around.