You never use QThread::sleep()
in the main thread because it prevents the GUI from being notified about the events and consequently does not behave correctly, the other questions argue correctly so I will not dedicate myself to it, my answer will be centered in giving you a solution that I think is the most appropriate with the use of QTimeLine
:
const QWidgetList buttons{ui->pushButton1, ui->pushButton2, ui->pushButton3};
QTimeLine *timeLine = new QTimeLine( 3000*buttons.size(), this);
timeLine->setFrameRange(0, buttons.size());
connect(timeLine, &QTimeLine::frameChanged, [buttons](int i){
buttons[i-1]->show();
});
connect(timeLine, &QTimeLine::finished, timeLine, &QTimeLine::deleteLater);
timeLine->start();
I do not recommend using processEvents()
because many beginners abuse it thinking it is the magic solution, for example the @cbuchart solution is incorrect because it solves the immediate problem but not the background, for example try to change the size of the window in those 9 seconds. Can you do it? Well, not since the QThread::sleep() is blocking.
Consider a bad practice to use QThread::sleep()
in the GUI thread, if you see it somewhere, mistrust.