简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM