PDA

View Full Version : Waiting for the Timer to emit Siganl timeout()



sujan.dasmahapatra
21st June 2010, 12:54
Dear Friends
I have a QTimer started, now I want wait till the timeout() signal emitted, how can I hang the program for a certain period of time but the timer started should keep emitting its signal. I am not sure how to achieve this , I have been trying something like this.

MainWindow::startTimer() {
QTimer * timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(update() ));
timer->start(60000);
}
MainWindow::update()
{
if() // if the job is done then
{
timer->stop();
}
else // wait for the next signal to be emitted after 1 min
{
waitcondition.wait(&mutex);
// Here the problem when its coming here its waiting for an uncertain time its not able to capture the timeout()
// signal anymore..... How can I achieve this please give me some hint fi anyone knows. Thanks
}
}

high_flyer
21st June 2010, 14:12
Did you really mean to override QWidget::update()?
If not you better name MainWindow::update() something else.

Also, why are you using a wait condition in that situation?
Usually you don't need threads if you use timers.

And please use code tags when posting code, its hard to read it this way.

Lesiok
21st June 2010, 14:12
What is waitcondition ?

sujan.dasmahapatra
21st June 2010, 19:52
waicondition is QWaitCondition. update() is a local slot MainWindow::update() not QWidget......how can stop excutation for sometime or hang the program but I want the timer to keep counting for time and emit timeout() signal ............Please tell me if you're not understing the situation. Thanks for the reply.

Lesiok
22nd June 2010, 09:13
Show us real code. Maybe You are blocking event loop in "long time job" and timer have no chance to generate signal.

high_flyer
22nd June 2010, 09:18
waicondition is QWaitCondition. update() is a local slot MainWindow::update() not QWidget
Again:
using a waint condition in your case, is probably the wrong way to go, and that is causing the problem.
If MainWindow is derived from QWidget (which it probably does if its a visible object), then you are overriding its update() method,and I don't think you really wanted to do that.