Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pause and restart the Qtimer on QT

I have a Ubuntu , and i'am working with IDE QT on C++ . I will to pause and resume the Qtimer , for exampe :

void Ordonnancer_les_taches::on_pushButton_clicked()
{

    connect(&dataTimer, SIGNAL(timeout()), this, SLOT(l_odonnancement()));
    dataTimer.start(5000);
}

How to Pause and how Restart ? give me an exmple

like image 362
StackTok Avatar asked Dec 18 '22 19:12

StackTok


1 Answers

Since there is no dedicated method to achieve this behaviour, you could do something like this (you may move it to a subclass PausableTime or so):

void pause() {
    int remaining = dataTimer.remainingTime();
    dataTimer.stop();
    dataTimer.setInterval(remaining);
}

void resume() {
    dataTimer.start();
}

Of course you then need to adjust the interval in your timeout slot again.

like image 182
Stanley F. Avatar answered Jan 02 '23 00:01

Stanley F.