PDA

View Full Version : Progressbar problem



thae
4th November 2006, 04:27
I have a function


void ex
{
long num = 100000;
for(int i=0;i<num;i++)
{
// do something
}
}

In the mainWindow when I call this function
I want to have a progress bar that indicates this function is running

I've used these code



void ex()
{
long RowCount = 60000;
QProgressDialog progress(this);
progress.setLabelText("ProgressBar");
progress.setRange(0, RowCount);
progress.setModal(true);
progress.show();
for (long row = 0; row < RowCount; ++row) {
progress.setValue(row);
qApp->processEvents();
if (progress.wasCanceled()) {
}
}
}

But the progress bar isn't running except it's increasing percentage
( it shows up but not progressing )

can't you help me !

thanks in advance !

stevey
4th November 2006, 06:54
Hi,

I just copied the content of your ex() function and stuck it in the main() of a test application.
It ran as expected with a progress bar incrementing the text value and the bar position.
So unfortunately there's not much I can say about why it's not working.

In terms of architecture though, it would be best not to have the wasCancelled() test inside you for loop. I stuck a message box in this test, but as soon as I clicked ok the loop continued, then the progress bar was still cancelled, so the messagebox kept being displayed.

This would be a better construct:


for (long row = 0; row < RowCount && !progress.wasCanceled(); ++row)
{
progress.setValue(row);
}
if(progress.wasCanceled())
{
QMessageBox::information(0, "Hi", "there", "OK");

}


Also, I left off qApp->processEvents(); and it worked fine, maybe that's causing an issue on your system?


Steve York

thae
4th November 2006, 09:53
Thanks Steve ! :D

But when the thread's finished, the progress bar still showing on the window
how can i hide it ?

stevey
4th November 2006, 11:12
So is it working now?



progress.hide();


It will obviously still exist until you exit the scope of the code block you create the QProgressDialog in, so depending on your circumstances, you may need to destroy the thing manually.

thae
4th November 2006, 11:48
thanks stevey !
It doesn't working because of my windows theme
when I change windows theme to XP theme It's Ok ! :)