PDA

View Full Version : Timer not timing out?



Mariane
2nd March 2006, 22:18
I have in the constructor:



MazeField::MazeField( QWidget *parent, const char *name ) : QWidget( parent, name ) {
(...)
recordingTimer = new QTimer( this, "recordingTimer" );
connect(recordingTimer,SIGNAL(timeout()),this,SLOT (updateRecordingTime()));
(...)
}


and in the same file, below:


void MazeField::updateRecordingTime() {
recordingTimerCount = (unsigned) time (NULL) - recordingTimerStart;
cout << "Recording time is " << recordingTimerCount << endl;
emit recordingTimeChanged(recordingTimerCount);
}


But this last bit doesn't seem to get reached, it doesn't even write the time...

Please help.

Mariane

jacek
2nd March 2006, 22:25
How do you start that timer?

Mariane
2nd March 2006, 22:26
Start? I thought they just started when declared :o

Mariane

wysota
2nd March 2006, 22:29
No, you have to start() them. And that's reasonable, because you can use a single timer multiple times.

Mariane
2nd March 2006, 22:30
Thank you very much.

Mariane

jacek
2nd March 2006, 22:30
Here's an example from Qt docs:
QTimer *timer = new QTimer( myObject );
connect( timer, SIGNAL(timeout()), myObject, SLOT(timerDone()) );
timer->start( 2000, TRUE ); // 2 seconds single-shot timer