Answer the question
In order to leave comments, you need to log in
Qt timer: what is the best way to make a countdown?
According to the functionality of the program, it assumes that the user will have 60 seconds to complete the action. You can also pause the counter. What is the best way to organize this: QTimer or a loop with a delay per second?
QTimer didn't really understand how to pause. There are many sources, but I could not do it.
And I didn't understand the delay. QThread or are there other ways? With QThread sleep also could not do it yet.
Please help.
Answer the question
In order to leave comments, you need to log in
DerClass::DerClass(QObject * parent)
: QObject(parent)
, mTimer(new QTimer(this)
{
connect(mTimer, SIGNAL(timeout()), this, SLOT(update()));
mTimer->start(1000);
mSecondsToEnd = 60;
}
DerClass::update()
{
--mSecondsToEnd;
if ( mSecondsToEnd > 0)
{
QStiring time = QString::number(mSecondsToEnd);
ui->backTimerTextLabel->setText("Осталось " + time + " секунд" );
}
else
{
mTimer->stop();
doWork();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question