Important: Please read the Qt Code of Conduct -

Before during and after...

  • Hi. Hope someone can help me with this.
    I know there are many articles out there explaining the sequence Slots and Signals are executed in, but this problem seems to be a bit different.

    My goal:
    To fully execute one set of commands before a while loop.
    Followed by a 10sec while loop during which I will have to repeat a second set of commands.
    Then execute a third set of commands.

    When I run the below code the delay works, but the phase1 and phase2 commands only execute after the delay.
    Why is this?

    @void MainWindow::on_StartBtn_clicked()
    ui->status_label->setText("Phase1 commands started");

    //set of commands that need to run before while loop executes.
    QTime FutureTime = QTime::currentTime();
    FutureTime = FutureTime.addSecs(10);
    while (QTime::currentTime()<= TempTime)
        ui->status_label->setText("Phase2 commands started");

    //Set of commands that need to repeat during the while loop

    ui->status_label->setText("Phase3 commands started");
    //set of things that need to execute after while loop is done


  • are you sure that the co0mmands are executed late and not just the ui is not updated?
    Changing the text of a label does not directly repaint, it only triggers an update which is done in one of the next repaints. If you want to see imediate results, call ui->status_label->repaint().

  • Thanks... You are on the ball. It was just the UI not updating. ;)

Log in to reply