PDA

View Full Version : Creating count down timer in Qt



TheIndependentAquarius
14th February 2012, 07:59
I wish to understand this line:
objTime->setHMS (0, objTime->addSecs (-1).minute (), objTime->addSecs (-1).second ());

How does this decrease the minutes and seconds?

From here: http://doc.qt.nokia.com/4.7/qtime.html#addSecs



QTime n(14, 0, 0); // n == 14:00:00
QTime t;
t = n.addSecs(70); // t == 14:01:10
t = n.addSecs(-70); // t == 13:58:50

`addSecs` function perhaps adds or subtracts seconds. Fine. But what does this do objTime->addSecs (-1).minute ()?

How does setHMS work (in the current case)?

Lesiok
14th February 2012, 12:11
Remember that QTime::addSecs() CREATES new QTime instance and don't change yourself.
So this is equivalent to :

QTime time_dec = objTime->addSecs (-1);
objTime->setHMS (0, time_dec.minute(), time_dec.second());