@Pl45m4 said in Problems with stacked Progress Dialogs:
Is the code above just an example or your real code?
I guess this question is asked because your source makes most of us squeam in horror. Others have already pointed out that you should use regular main() for Qt programs. It doesn't help that you are creating your own argc and argv variables to be passed to the QApplication constructor.
It is really bad practice to use global variables. Everything above your main function should go into a MainWindow class derived from QMainWindow.
You should also avoid using pointers whereever possible. In your particular case there is no reason for Application and mainWindow to be pointers (but mainWindow should also be a local variable). Theoretically, you are leaking memory. (Practically, it doesn't matter because the OS will clean up after you.)
@JanLaloux said in Problems with stacked Progress Dialogs:
I don't agree. If there is only the global progress window (no step progress shown), the progress dialog remains responsive and it can be cancelled at any time, no other thread is needed. You have of course to check regularly if the cancel button was pressed, and the QProgressDialog::canceled signal is connected to a slot for this.
My experience is totally different. I have never seen a smooth animation of the progress bar when doing it this way. And you also have to hit the cancel button at the right time to be able to cancel progress. This is the reason why you'll find many discussions in this forum using QApplication::processEvents to make the progress dialog somehow work properly. But, everybody will tell you not to use QApplication::processEvents. Your actual computation will take way longer if you do this. The only proper way to do this is actually to use a separate thread. I have simplified this for myself and put it into a library: https://github.com/SimonSchroeder/QtThreadHelper. Just use workerThread([](){ /* do stuff */ }); to run any function in another thread (this is derived from QThread::create followed by start()). If you want to wait for the work to finish, use workerThreadJoin() instead. There's another helper guiThread() which I typically use to update the progress bar. You'll find an example in the readme of my lib.