PDA

View Full Version : Qtimer problem



bikalpa
28th September 2012, 12:07
i am using qtimer for traffic light change in junction. i have created four state and each state run for some second.
But after sometime it hang and when i see task manager the memory consumed by that application rises.
i have created four state n each state is called from previous state.please tell me where i am wrong..







timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(state1() ))

void Dialog::state1()
{
timer->stop();

//code to draw appropriate traffic light

connect(timer,SIGNAL(timeout()),this,SLOT(state2() ));
timer->start(2000);
}

void Dialog::state2()
{
timer->stop();

//code to draw traffic light

connect(timer,SIGNAL(timeout()),this,SLOT(state3() ));
timer->start(2000);
}

void Dialog::state3()
{
timer->stop();

//code to draw appropriate traffic light

connect(timer,SIGNAL(timeout()),this,SLOT(state4() ));
timer->start(2000);
}
void Dialog::state4()
{
timer->stop();

//code to draw appropriate traffic light

connect(timer,SIGNAL(timeout()),this,SLOT(state1() ));
timer->start(2000);
}

pradeepreddyg95
28th September 2012, 12:38
try use disconnect(timer,SIGNAL(timeout()),this,SLOT(state 1()) before calling connect(timer,SIGNAL(timeout()),this,SLOT(state2() )); same process for all ...
i think it will help for you ...

wagmare
28th September 2012, 13:32
use connect only once ... every time u call the state() function u r establishing a new connection .. and all the connect will run concurrently .. or disconnect like Mr.pradeep said

Lesiok
28th September 2012, 14:31
Do not use the connect / disconnect, use QTimer::singleShot like this :
QTimer::singleShot(2000,this,SLOT(state1() ));

void Dialog::state1()
{
//code to draw appropriate traffic light
QTimer::singleShot(2000,this,SLOT(state2() ));
} and so on.

bikalpa
29th September 2012, 04:11
Thanks. It really help me.
I also have another problem. i am using open cv to play video.i am displaying video using Qlabel.
The open cv use infinite loop to play the video. But i want to implement above traffic light in parallel . i want to show the
video of four side of the junction and using image processing i want to control the traffic light.
plz help.

ChrisW67
1st October 2012, 02:10
Please tell us what the problem is, why you think it is a problem, and what you have read/done to try to sort it out.