When I create slots by name with this kind of syntax:
on_<widgetname>_clicked();
If I want to display a particular widget Inside this function it won't display until it reaches the end of the function.
That is, when I create the following function:
void MyWindow::on_myWidget_clicked()
{
// the stackedWidget is composed of:
// page_1 with myWidget
// page_2
ui->stackedWidget->setCurrentWidget(ui->page_2);
waitSomeTime();
}
whith
void MyWindow::waitSomeTime()
{
QThread t;
t.sleep(2); // Wait 2 seconds to see which line is going to be executed first.
}
When the code is launched, the 2 seconds elapsed first and only then the page_2 is displayed.
Why the line
ui->stackedWidget->setCurrentWidget(ui->page_2);
is not executed first?