PDA

View Full Version : Progressdialog does not update?



marc2050
13th May 2011, 02:25
Hi.

I've a long calculation that takes time.
I tried using progressdialog to show users the status of the calculation.
But the progressdialog apear on screen. after than it just doesnt update
until the entire calculation finishes. Here's my codes. What could be wrong?

QProgressDialog pd;
pd.setRange(0,100000);
pd.setLabelText("Long calculations...");
pd.setValue(0);
pd.show();


In the calculation function, I've
pd.setValue(somevalue) where somevalue is the value I obtained.
pd.show()

On the screen, what i see is just a progress dialog, which does not even have the bar moving at all. It sort of like those you see when something doesnt complete and freeze. And when all is done, the dialog just closes.

What is really happening? Any advise?
Thanks.

ChrisW67
13th May 2011, 02:49
You don't need to call show() every time you updated the value. What are the actual values of "somevalue" that you "obtained"? Are they in the range 0 to 100000?

This, for example, works fine:


#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QProgressDialog pd;
pd.setRange(0,100000);
pd.setLabelText("Long calculations...");
pd.setValue(0);
pd.show();

for (int i = 0; i < 100000000; ++i) {
if (i % 1000 == 0) {
int somevalue = i / 1000;
pd.setValue(somevalue);
}
}
}

marc2050
13th May 2011, 10:35
I did what you wrote. Yes. It works when you're doing a simple loop. But once you place the pd.setValue(somevalue) in a more complex situation, the progress dialog does not get updated. Is this a bug? It looks to me that the refresh of the progressdialog is not given chance to update itself. Is there something we need to get this widget refresh or update?

ChrisW67
13th May 2011, 11:23
What "more complex situation" is going to stop the progress bar updating? The progress bar setValue() call ensures that any pending repaint is run before returning.

Is the call to setValue() actually being called? Are the values in range?