PDA

View Full Version : QT QTimer



sonulohani
16th May 2013, 07:43
How to pause and resume QTimer?

Lykurg
16th May 2013, 09:13
As far as I know you cant. Use QTimeLine instead.

Lesiok
16th May 2013, 10:31
And what is wrong with the methods start() and stop() ?

Santosh Reddy
16th May 2013, 11:27
Can you try this


class Timer : public QTimer
{
Q_OBJECT
public:
explicit Timer(QObject * parent)
: QTimer(parent)
, mRemainingTime(0)
{
;
}

public slots:
void pause(void)
{
mRemainingTime = remainingTime();
stop();
}

void resume(void)
{
start(mRemainingTime);
}

private:
int mRemainingTime;
};


One downside is that the interval() is not consistent through out the Timer's running cycle, interval() changes when ever time is pause()ed and resume()ed.

ChrisW67
17th May 2013, 01:18
QTimer::remainingTime() is only available in Qt 5