Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QThread and double closing QProgressDialog
Forum Update on Monday, May 27th 2025

QThread and double closing QProgressDialog

Scheduled Pinned Locked Moved Solved General and Desktop
qthreadqprogressdialog
5 Posts 3 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kegon
    wrote on 23 Mar 2017, 18:34 last edited by kegon
    #1

    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 ?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 23 Mar 2017, 18:41 last edited by
      #2

      Can you post your code?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • K Offline
        K Offline
        kegon
        wrote on 24 Mar 2017, 12:21 last edited by
        #3

        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 ?

        J 1 Reply Last reply 24 Mar 2017, 12:50
        0
        • K kegon
          24 Mar 2017, 12:21

          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 ?

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 24 Mar 2017, 12:50 last edited by
          #4

          @kegon

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


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          K 1 Reply Last reply 27 Mar 2017, 19:25
          1
          • J J.Hilk
            24 Mar 2017, 12:50

            @kegon

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

            K Offline
            K Offline
            kegon
            wrote on 27 Mar 2017, 19:25 last edited by
            #5

            @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.

            1 Reply Last reply
            0

            5/5

            27 Mar 2017, 19:25

            • Login

            • Login or register to search.
            5 out of 5
            • First post
              5/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved