Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Model QProgressDialog jams when updated from separate thread
Qt 6.11 is out! See what's new in the release blog

Model QProgressDialog jams when updated from separate thread

Scheduled Pinned Locked Moved Solved Language Bindings
9 Posts 3 Posters 3.3k Views 1 Watching
  • 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.
  • W Offline
    W Offline
    Willw
    wrote on last edited by Willw
    #1

    Using PySide2 I'm settings up a QThread to do a biggish job and update a QProgressDialog via signals. If the updates are emitted relatively slowly (once a second or so) this works fine, if they are more frequent (5-10 times a second) the QProgressDialog will stop updating at some point. If this happens the it will remain jammed for some time after the thread has finished its work. It will eventually come back to life and close properly.

    This is an example of what I'm doing.

    class SomeWidget(QtWidgets.QWidget):
    
        def __init__(self, parent=None):
            super(SomeWidget, self).__init__(parent)
            self.thread = QtCore.QThread()
            
            self.progress = QtWidgets.QProgressDialog("", "Cancel", 0, 100, self)
            self.progress.setWindowModality(QtCore.Qt.WindowModal)
            self.progress.setAutoClose(True)
            self.progress.setAutoReset(True)
            
            self.worker = Worker()
            self.worker.moveToThread(self.thread)
            self.worker.update_progress.connect(self.progress.setValue)
            self.worker.done.connect(self.work_done)
            self.thread.started.connect(self.worker.do_the_thing)
            
            self.thread.start()
            
        def work_done(self):
            self.thread.exit()
            print("Done")
    
    
    class Worker(QtCore.QObject):
        update_progress = QtCore.Signal(int)
        done = QtCore.Signal()
        
        def do_the_thing(self):
            for ii in range(1, 101):
                time.sleep(0.1)  # Simulate work
                self.update_progress.emit(ii)
            self.done.emit()
    

    This issue is unpredictable. It will jam at different points each time and occasionally it will make it through without stopping. If I do not set the QProgressBar modality to WindowModal, it works without issue. I assume that the modal progress bar affects the way signals are processed, but I'm not certain what the better way to hook this up would be.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What version of PySide2 / PyQt5 are you using ?
      On what OS ?
      How did you install it ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Willw
        wrote on last edited by
        #3

        Hi, thanks.

        It's PySide2 5.15.0 running on Windows installed via pip.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you check if that also happens with the previous version ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          JonBJ 1 Reply Last reply
          0
          • W Offline
            W Offline
            Willw
            wrote on last edited by
            #5

            You appear to be correct. It does seem to work properly in 5.14.2.3. Should this be a bug report then?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Yes, this looks like a regression. Please provide a complete minimal example so the developer will be able to more easily get started.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • SGaistS SGaist

                Can you check if that also happens with the previous version ?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @SGaist said in Model QProgressDialog jams when updated from separate thread:

                Can you check if that also happens with the previous version ?

                How could you possibly have guessed that would be the right answer in this case?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @JonB in the case at hand, the code is correct and the logic as well. The worker object approach makes it so that the signals and slots mechanism should work correctly. 5.15.0 being the latest release, the first thing to do is try the previous one to see if something broke as it's the case here.

                  One other thing that could be done is to implement the same code in C++ to see if it's binding or library related.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  JonBJ 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    @JonB in the case at hand, the code is correct and the logic as well. The worker object approach makes it so that the signals and slots mechanism should work correctly. 5.15.0 being the latest release, the first thing to do is try the previous one to see if something broke as it's the case here.

                    One other thing that could be done is to implement the same code in C++ to see if it's binding or library related.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @SGaist It's just that your predictions are uncanny, i.e. scary ;-)

                    1 Reply Last reply
                    0

                    • Login

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