QThread and double closing QProgressDialog
-
Hi, I need some help with the design of my program.
The issue with the current design is that when I cancel a QProgressDialog it re-appears and then automatically disappears.
My program has a slow function, so I put it into a QThread to keep the GUI thread responsive; as follows:
- Main thread sets up a subthread to run the function and (the main thread) opens a QProgressDialog
- Function starts working and emits progress values
- Main thread receives progress values and updates dialog
- User hits cancel on dialog, main thread signals subthread to stop
- Subthread sends signal back to say it has stopped
I think what is happening is that the main thread receives a progress signal from the subthread after the cancel button is being clicked. At this point the main thread is in the middle of the function that is handling the previous progress value.
The progress dialog closes itself (due to the cancel button) but receives a new value so reopens. The dialog seems to close itself automatically afterwards.
I tried explicitly calling close() on the dialog but it didn't help.
Can someone propose a better design so I can avoid this problem ?
-
Thanks, I was checking
wasCanceled()
in several places but not just before applying the new value. I was rather sceptical that it would work, but it did.Still, I would have liked to have learned a better scheme for handling the progress.