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. Non-blocking progress dialog during huge amount of non-controllable calculations.
Qt 6.11 is out! See what's new in the release blog

Non-blocking progress dialog during huge amount of non-controllable calculations.

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 1.5k 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.
  • I Offline
    I Offline
    IsAnton
    wrote on last edited by IsAnton
    #1

    I implemented a widget/dialog, which is just a gif animation inside (CircularProgressDlg). Our application consists of Login dialog part and MainWindow part. Between login is accepted and MainWindow is fully loaded there are 5 to 10 seconds of huge init() function.

    What I need is to launch my CircularProgressDlg when login is accepted, and I need it to animate it's gif non-blocking. I can't use "update" or "processEvents" inside this huge "init" function, cause it is very complex inside and it won't be smooth enough.

    It looks very needful that this type of dialogs, detached from main event loop, exist! So how to achieve that?
    I understand that I can create a detached Process with this CircularProgressDlg, but let's leave this way to the end.

    What are other ways?
    We use QtWidgets, but maybe I can implement small QML dialog for such cases if, of course, QML will solve my problem. Will it?
    Which options do I have?

    1 Reply Last reply
    0
    • I IsAnton

      @jsulm I can't create just Thread and move huge pending logic there, logic is very complex and mixed with Gui interaction, it has to be in main thread. I mean exactly the Process, in which a different event loop will exist, for my progress dialog.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @IsAnton Your progress dialog will be in the same process. I think you mix some things here: a process is an application in execution. If this application shows a progress dialog it is still same process.
      "logic is very complex and mixed with Gui interaction" - well, it should be still possible to move this logic into another thread. You just need to make sure that this thread does not access the UI directly. Instead emit signals in that thread when needed and react on this signals in main thread.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Hi,

        As soon as you have activities that blocks the event loop, you won't be able to do what you want. Move the processing to a different thread or use a static mean of showing that your application is busy.

        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
        2
        • I Offline
          I Offline
          IsAnton
          wrote on last edited by IsAnton
          #3

          @SGaist Yes, you are right Event loop is blocked. Ok, I understand, I have to create Process, if I need animated progress. Will see other recommendations then will close topic.

          jsulmJ 1 Reply Last reply
          0
          • I IsAnton

            @SGaist Yes, you are right Event loop is blocked. Ok, I understand, I have to create Process, if I need animated progress. Will see other recommendations then will close topic.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @IsAnton said in Non-blocking progress dialog during huge amount of non-controllable calculations.:

            I have to create Process

            Thread not process most likely

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            I 1 Reply Last reply
            0
            • jsulmJ jsulm

              @IsAnton said in Non-blocking progress dialog during huge amount of non-controllable calculations.:

              I have to create Process

              Thread not process most likely

              I Offline
              I Offline
              IsAnton
              wrote on last edited by
              #5

              @jsulm I can't create just Thread and move huge pending logic there, logic is very complex and mixed with Gui interaction, it has to be in main thread. I mean exactly the Process, in which a different event loop will exist, for my progress dialog.

              jsulmJ 1 Reply Last reply
              0
              • I IsAnton

                @jsulm I can't create just Thread and move huge pending logic there, logic is very complex and mixed with Gui interaction, it has to be in main thread. I mean exactly the Process, in which a different event loop will exist, for my progress dialog.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @IsAnton Your progress dialog will be in the same process. I think you mix some things here: a process is an application in execution. If this application shows a progress dialog it is still same process.
                "logic is very complex and mixed with Gui interaction" - well, it should be still possible to move this logic into another thread. You just need to make sure that this thread does not access the UI directly. Instead emit signals in that thread when needed and react on this signals in main thread.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                I 1 Reply Last reply
                2
                • jsulmJ jsulm

                  @IsAnton Your progress dialog will be in the same process. I think you mix some things here: a process is an application in execution. If this application shows a progress dialog it is still same process.
                  "logic is very complex and mixed with Gui interaction" - well, it should be still possible to move this logic into another thread. You just need to make sure that this thread does not access the UI directly. Instead emit signals in that thread when needed and react on this signals in main thread.

                  I Offline
                  I Offline
                  IsAnton
                  wrote on last edited by IsAnton
                  #7

                  @jsulm Codebase of our initialization is quite big, I would need weeks or even more to refactor it correctly, to separate server interactions and GUI update.
                  I am just thinking of an easy way to create nonblocking dialog on top of main event loop.
                  Look in https://doc.qt.io/qt-5/qeventloop.html there is a description:
                  "At any time, you can create a QEventLoop object and call exec() on it to start a local event loop. From within the event loop, calling exit() will force exec() to return."

                  It looks like I can create another event loop and put my Dialog there! Is it real?

                  jsulmJ J.HilkJ 2 Replies Last reply
                  0
                  • I IsAnton

                    @jsulm Codebase of our initialization is quite big, I would need weeks or even more to refactor it correctly, to separate server interactions and GUI update.
                    I am just thinking of an easy way to create nonblocking dialog on top of main event loop.
                    Look in https://doc.qt.io/qt-5/qeventloop.html there is a description:
                    "At any time, you can create a QEventLoop object and call exec() on it to start a local event loop. From within the event loop, calling exit() will force exec() to return."

                    It looks like I can create another event loop and put my Dialog there! Is it real?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @IsAnton I don't see how creating a second event loop will help you.
                    https://doc.qt.io/qt-5/qeventloop.html#exec is a blocking call! As soon as you call it in your initialisation code you will block your initialisation code.
                    What could work (but is an ugly work-around) is to make sure you call https://doc.qt.io/qt-5/qcoreapplication.html#processEvents regularly and often enough in your initialisation code to give the event loop time to process events.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    5
                    • I IsAnton

                      @jsulm Codebase of our initialization is quite big, I would need weeks or even more to refactor it correctly, to separate server interactions and GUI update.
                      I am just thinking of an easy way to create nonblocking dialog on top of main event loop.
                      Look in https://doc.qt.io/qt-5/qeventloop.html there is a description:
                      "At any time, you can create a QEventLoop object and call exec() on it to start a local event loop. From within the event loop, calling exit() will force exec() to return."

                      It looks like I can create another event loop and put my Dialog there! Is it real?

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #9

                      @IsAnton
                      what you can to is quite literally an other process.

                      Or more precise an other QApplication that consists only out of a waiting animation.

                      I do that in one of my Applications.

                      I have 2 executables a splash screen and the main app. On start up I start the splashscreen via QProcess and after initialization of the main App I kill the process

                      Only downside, depending on the OS you may end up with 2 Icons in your hotbar.


                      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.

                      1 Reply Last reply
                      2
                      • I Offline
                        I Offline
                        IsAnton
                        wrote on last edited by
                        #10

                        @J-Hilk @jsulm @SGaist Thanks to everyone. We decided to make things right and refactor loading and updating our widgets in a non-blocking way.

                        1 Reply Last reply
                        1

                        • Login

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