Nominate our 2022 Qt Champions!

Updating 'Current Elapsed Time' in the GUI

  • Hi there, I currently have a program which has two main sections, the mainWindow class which is the GUI portion of my program, and a SokoGenerator class which is running on a QThread so that the GUI can update while the Generator is running.

    Id like to start a timer once a button is clicked, and then constantly update the GUI with the current elapsed time of the program, and then stop updating the timer once the Generator has finished it's execution. I tried to use the QTime Class but I was not very successful as I couldn't calculate the time difference using the following code:

    QTime currentTime = QTime::currentTime();
    QTime diffTime = currentTime - startTime;
    QString timeString = diffTime.toString("hh : mm : ss");
    ui->label_GenerationTime->setText("Current Generation Time: " + timeString);

    What is the best way to update a GUI Label with the current elapsed time, and then stop updating once the Generator has finished running?

    Thanks, RBrNx

  • Look at this thread.

Log in to reply