PDA

View Full Version : problem with QTimer



salmanmanekia
13th August 2008, 14:01
i have written a piece of code in which i update my view after every millisecond ,i do this by clicking a button,but when i reclick the button the view is updated twice the speed of its previous update and this speed seems to increase by every click..here is some code to give you a idea..


QTimer *timerProg;

..
timerProg = new QTimer();
..

void Progress::startProgress()
{
rec_button = TRUE;
connect(timerProg,SIGNAL(timeout()),this,SLOT(adva nce()));
timerProg->start(ROTATION_TIME);
}

void Progress::advance()
{
if(rotation < 260)
{
rotation += ANGLE_INCREASE;
rotation %= TOTAL_ROTATION;
update();
}
else
{
timerProg->stop();
rotation = -90;
}
}

wysota
13th August 2008, 14:22
You connect to the timer each time you click the button, so after 10 clicks you'll timer will be connected 10 times, effectively multiplying the number of times the slot is called. It is enough to connect once when you create the timer and then only start the timer if it is not already running.