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 :
{
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);
}
}
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);
}
}
To copy to clipboard, switch view to plain text mode
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 ?
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;
}
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;
}
To copy to clipboard, switch view to plain text mode
Bookmarks