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. progress bar not updating during iterations but updating once the process is completed?
Forum Updated to NodeBB v4.3 + New Features

progress bar not updating during iterations but updating once the process is completed?

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 2.9k 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Only one thing: You must not access or try to modify widgets outside the main gui thread. So fix your code and use proper signals/slots instead.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    A 1 Reply Last reply
    2
    • Christian EhrlicherC Christian Ehrlicher

      Only one thing: You must not access or try to modify widgets outside the main gui thread. So fix your code and use proper signals/slots instead.

      A Offline
      A Offline
      aravmadd
      wrote on last edited by
      #3

      @Christian-Ehrlicher You mean since i am updating my progress bar with iteration number inside calib function(which is running in another thread) so my progress bar update is not working as intended right? . Even If i run my calib function in the same thread it is giving me same kind of output!

      I didnt change anything in SIGNAL and SLOT implementation. (It was the same as mentioned in one of the screenshots above.)

      Please correct me if i am wrong!.

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #4

        When you run your loop in the gui thread then the ui is blocked since you block the eventloop.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        A 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          When you run your loop in the gui thread then the ui is blocked since you block the eventloop.

          A Offline
          A Offline
          aravmadd
          wrote on last edited by
          #5
          This post is deleted!
          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #6

            Move your heavy calculation into an own thread as shown in the documentation and the examples there.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            A 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              Move your heavy calculation into an own thread as shown in the documentation and the examples there.

              A Offline
              A Offline
              aravmadd
              wrote on last edited by aravmadd
              #7

              @Christian-Ehrlicher Hi!, I didnt change anything in the code as mentioned in the question. This comment is rather to get some more clarity for myself. I think i moved my heavy calculation part into the different thread. But inside this new thread i have two for loops and inside my second loop i want to pass iteration number by normalizing it to 0-100 to progressbar. So I am still confused why it is happening like this. And as per what i found is Threads can run an event loop.

              Sorry for being dumb :-( . The more i go to documenation and some questions in stack and qt forum it is making me more confuse :-). May be because i am beginner :-)

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @aravmadd said in progress bar not updating during iterations but updating once the process is completed?:

                So I am still confused why it is happening like this

                Because you modify ui stuff from another thread which is not allowed. Use signals and slots as I already wrote 3 days ago.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                A 1 Reply Last reply
                1
                • Christian EhrlicherC Christian Ehrlicher

                  @aravmadd said in progress bar not updating during iterations but updating once the process is completed?:

                  So I am still confused why it is happening like this

                  Because you modify ui stuff from another thread which is not allowed. Use signals and slots as I already wrote 3 days ago.

                  A Offline
                  A Offline
                  aravmadd
                  wrote on last edited by
                  #9

                  @Christian-Ehrlicher Hi Thanks I am working on implementing it in worker class. I am trying to create worker class and do some intensive work there.

                  I have a small question here , how can i get information from ui into worker class? For example if i have some text in LineEdit i need to get this information in worker class.

                  jsulmJ 1 Reply Last reply
                  0
                  • A aravmadd

                    @Christian-Ehrlicher Hi Thanks I am working on implementing it in worker class. I am trying to create worker class and do some intensive work there.

                    I have a small question here , how can i get information from ui into worker class? For example if i have some text in LineEdit i need to get this information in worker class.

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

                    @aravmadd said in progress bar not updating during iterations but updating once the process is completed?:

                    how can i get information from ui into worker class?

                    via signals/slots

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

                    A 1 Reply Last reply
                    2
                    • jsulmJ jsulm

                      @aravmadd said in progress bar not updating during iterations but updating once the process is completed?:

                      how can i get information from ui into worker class?

                      via signals/slots

                      A Offline
                      A Offline
                      aravmadd
                      wrote on last edited by aravmadd
                      #11

                      @jsulm Thanks it took me some time to figure it out on correct implementation of signals and slots.

                      Now its working.

                      What i did was

                      I ran the heavy calculation function in another thread using QtConcurrent.

                      Then from the heavy function i emitted signal , with the emitted signal i defined one slot(in my widget.cpp) which updates my progress bar.
                      Here is how it looks

                      connect(this, &Widget::updateProgress, this, &Widget::onProgressValueChanged);
                      

                      After this i connected signal and slot properly it worked fine.

                      Initially i thought it is not working because the update is too fast that i cannot see real update in progress bar, then i only updated at 25 percent and 50 percent and 75 and 100 percent to my progress bar. Then i can see the progress in progress bar.

                      1 Reply Last reply
                      3

                      • Login

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