PDA

View Full Version : Simple QProgressDialog without multi threading



fatecasino
29th March 2011, 20:22
I am trying to set up a simple QProgressDialog while a for loop is taking place without using mutlithreading. I followed the Keeping the GUI Responsive (http://www.qtcentre.org/wiki/index.php?title=Keeping_the_GUI_Responsive#Perform ing_Long_Operations) but I cannot get it working:


QProgressDialog progress("Copying files...", "Abort Copy", 0, myModel->model->rowCount(), this);
progress.setWindowModality(Qt::WindowModal);
// progress.show();


for( int i = 0; i< linesetIndexes.size()-1; i++ )
{

progress.setValue(i);
QCoreApplication::processEvents();
if (progress.wasCanceled())
break;
......//proccessing


}

wysota
30th March 2011, 00:11
Please explain what you mean by "cannot get it working". The progress dialog shouldn't need processEvents(), the call is embeded into QProgressDialog::setValue().

ChrisW67
30th March 2011, 03:15
A possible issue is that you set the progress dialog's range to 0 to myModel->model->rowCount() and then proceed to feed it values from 0 to linesetIndexes.size()-2 in your for loop. Only you know if the two upper bounds are related to each other.

fatecasino
1st April 2011, 04:22
@wysota: The for-loop does some heavy calculations. At that phase, the application looks like it hangs, but it does not. At the end of the calculations the application comes back to life and presents them. It is only then when the progress bar appears with value 100%. If I uncomment:

// progress.show();
then the box of the progress bar appears with the window title and nothing else in it. At the end of the calculations the progress bar appears again with value 100%

@ChrisW67: the linesetIndexes.size()-1 is known before the for-loop starts and it is always greater than 5 or six. So there it should be some progress :(

fatecasino
4th April 2011, 22:28
any ideas?

wysota
4th April 2011, 22:29
I'd have to see a minimal compilable example reproducing the problem.

ChrisW67
4th April 2011, 23:22
@ChrisW67: thmyModel->model->rowCount()e linesetIndexes.size()-1 is known before the for-loop starts and it is always greater than 5 or six. So there it should be some progress :(

I think you have missed the point. The range of values you have told the dialog to expect and the range of values you subsequently feed it through calls to setValue may not be comparable, and you haven't addressed that point. For example: if myModel->model->rowCount() is 1000 and you feed the values from 0 to 5 or 6 into the progress dialog through setValue() then the bar is hardly going to move significantly even if it is working.

SixDegrees
4th April 2011, 23:33
Another problem: the "processing" step, left blank in the example code, might take varying amounts of time to complete per iteration. If execution time per iteration varies widely, you'll get hangs between some updates and not others.