Qt QProgressBar indeterminate

c++, qt

Solution

I think one thing that you might need is that you call `QApplication::processEvents()` while looping over your entries. Quoting from `QCoreApplication` docs:

You can call this function occasionally when your program is busy performing a long operation (e.g. copying a file).

and I think in this particular case the application will not update the appearance of your `QProgressDialog` while it is busy performing the long operation unless you call `QApplication::processEvents()`.

If you have fixed range and you call `setValue()` as your loop progresses (quoting from the `QProgressDialog` docs):

If the progress dialog is modal (see QProgressDialog::QProgressDialog()), setValue() calls QApplication::processEvents()

(I am omitting here the warning which cautions that this can cause issues with re-entrancy).`

Note that when I tried your code it created a dialog like what you would expect if you only remove the line

`dlg.setBar( new QProgressBar() );`

As was said in another answer, `QProgressDialog` has its own `QProgressBar` so unless you have special requirements, this should do what you need.

Problem

My application needs to do some operations which might take a second but might also take 10 minutes. For this purpose I need to show a QProgressDialog with indeterminate QProgressBar during the operation. ``` QProgressDialog dlg( this ); dlg.setBar( new QProgressBar() ); dlg->setMaximum( 0 ); dlg->setMinimum( 0 ); dlg.setModal( true ); dlg.show(); //operation ... dlg.close(); ``` During my operation the dialog shows up, is transparent, has no progressbar and after the operation it closes. Does anyone know what I can do to show a modal dialog which prevents the user from interacting with the application and which shows the user an indeterminate progressbar?

Original source