PDA

View Full Version : Can I call setRange multiple times for QProgressBar ?



elizabeth.h1
29th April 2010, 17:03
Hello

I have long operation that needs to report about progress. The operation have multiple loops inside itself, and each loop counter is not known until runtime. So, I was thinking that I can call setRange multiple times on my progress bar , with the different counter values.Something like this , pseudo code :



void MyLongProcedure(QProgressBar* bar)
{

int counter1=calc_counter1();
bar->setRange(1,counter1);
for(int i=0;i<counter1;i++)
{
// do something here
bar->SetValue(i);
}

int counter2=calc_counter2();
bar->setRange(1,counter2);
for(int i=0;i<counter2;i++)
{
//do something here
bar->setValue(counter1+i);
}

}

I am expecting I can do this, and the progress bar should update itself accordingly, i.e continue where it ends with the first loop.

I made simple test , with QProgressDialog since it uses qProgressBar to see if this is supported, but
after the first loop, the progress bar is reset, and with the second loop it starts anew. Whats wrong ?


QProgressDialog dlg;
dlg.setWindowModality(Qt::WindowModal);
dlg.setMinimumDuration(0);
dlg.setRange(1,20000);
for(int i=1;i<10000;i++)
{
// do something here
dlg.setValue(i);

if (dlg.wasCanceled())
break;
}

dlg.setRange(1,30000);
for(int j=0;j<20000;j++)
{
//do something here
dlg.setValue(1000+j);
if (dlg.wasCanceled())
break;
}

tbscope
29th April 2010, 17:24
Just to make sure, you do see that the setvalue in the second loop adds only 1000 and not 10000?

elizabeth.h1
30th April 2010, 08:18
That was it. How silly, I missed one zero. Thank you