PDA

View Full Version : How can i delay a function?



firenet
24th January 2007, 02:37
I want to paint how the value change to newValue , so when the value increase a step,i want to repaint it .I use the code like this ,but it didn't work well:When the value increase ,it didn't repaint;but when the value changed to newValue, it repainted 10 times. Where was wrong? Thanks


void Board::setValue(int newValue)
{
int i=1;
int oldValue=value;
for(i=1;i<11;i++)
{
value=oldValue+(newValue-oldValue)/10*i;
qDebug("%d",value);
QTimer::singleShot(1000,this,SLOT(repaint()));
// repaint();
// sleep(1);
}

}

Mad Max
24th January 2007, 03:03
Because repaint function inside a loop. :)

aamer4yu
24th January 2007, 03:58
update() and QCoreApplication::processEvents()
might help you...
use the update to repaint... and processEvents to reflect the updation..