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:

    1. Main thread sets up a subthread to run the function and (the main thread) opens a QProgressDialog
    2. Function starts working and emits progress values
    3. Main thread receives progress values and updates dialog
    4. User hits cancel on dialog, main thread signals subthread to stop
    5. 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 ?



  • Can you post your code?



  • Sorry, I can't post code.

    This is a design question: is there an alternative/better way of handling progress from a task in another thread ?



  • @kegon

    can't you just check, before applying a new value, if wasCanceled() returns true or nor?



  • @J.Hilk

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.