Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Progress Bar value not getting updated
Forum Update on Monday, May 27th 2025

QML Progress Bar value not getting updated

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
11 Posts 3 Posters 1.7k 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.
  • M Offline
    M Offline
    minju
    wrote on 23 Jan 2020, 04:54 last edited by
    #1

    Hello,
    I have a progress bar in qml and trying to update the value form C++. I have created a class derived from Q_OBJECT. Through Q_PROPERTY I am reading and setting the progress value. This Value is continuously updated and emitted. In QML, the value is getting updated as I checked the onValueChanghed slot but in UI the progress is not shown, the progress bar is still at 0.

    Can anyone help?
    Thanks in advance

    J 1 Reply Last reply 23 Jan 2020, 06:11
    0
    • M minju
      23 Jan 2020, 04:54

      Hello,
      I have a progress bar in qml and trying to update the value form C++. I have created a class derived from Q_OBJECT. Through Q_PROPERTY I am reading and setting the progress value. This Value is continuously updated and emitted. In QML, the value is getting updated as I checked the onValueChanghed slot but in UI the progress is not shown, the progress bar is still at 0.

      Can anyone help?
      Thanks in advance

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 23 Jan 2020, 06:11 last edited by
      #2

      @minju Is it possible that you're blocking the event loop? Can you show your C++ code where you change the value?

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

      M 1 Reply Last reply 23 Jan 2020, 07:40
      1
      • J jsulm
        23 Jan 2020, 06:11

        @minju Is it possible that you're blocking the event loop? Can you show your C++ code where you change the value?

        M Offline
        M Offline
        minju
        wrote on 23 Jan 2020, 07:40 last edited by
        #3

        @jsulm
        Thanks for the reply
        The progress value is updated in an while loop. I had used infinite loop,this lead to the progress bar from not getting updated even though the value was set. When I replaced it with a finite loop the progress bar shows the progress only once.

        In my while loop I am transmitting data for a definite number of times. Hence for every iteration I require the progress bar to show the progress from 0 to 1.

        Kindly help
        Thanks

        J K 2 Replies Last reply 23 Jan 2020, 07:45
        0
        • M minju
          23 Jan 2020, 07:40

          @jsulm
          Thanks for the reply
          The progress value is updated in an while loop. I had used infinite loop,this lead to the progress bar from not getting updated even though the value was set. When I replaced it with a finite loop the progress bar shows the progress only once.

          In my while loop I am transmitting data for a definite number of times. Hence for every iteration I require the progress bar to show the progress from 0 to 1.

          Kindly help
          Thanks

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 23 Jan 2020, 07:45 last edited by jsulm
          #4

          @minju said in QML Progress Bar value not getting updated:

          The progress value is updated in an while loop

          That's the issue.
          Do not do such things in event driven applications an GUI thread!
          If you block the event loop with such an "update" loop events will not be executed (also such for GUI updates).
          How to solve your problem depends on the implementation of your C++ part which I don't know as you did not post the code and did not explain what exactly you're doing there.

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

          M 1 Reply Last reply 23 Jan 2020, 09:29
          0
          • M minju
            23 Jan 2020, 07:40

            @jsulm
            Thanks for the reply
            The progress value is updated in an while loop. I had used infinite loop,this lead to the progress bar from not getting updated even though the value was set. When I replaced it with a finite loop the progress bar shows the progress only once.

            In my while loop I am transmitting data for a definite number of times. Hence for every iteration I require the progress bar to show the progress from 0 to 1.

            Kindly help
            Thanks

            K Offline
            K Offline
            KroMignon
            wrote on 23 Jan 2020, 07:50 last edited by
            #5

            @minju said in QML Progress Bar value not getting updated:

            In my while loop I am transmitting data for a definite number of times. Hence for every iteration I require the progress bar to show the progress from 0 to 1.

            To work, signals/slots needs time... So if you locking the thread in a loop, there is no chance for the QEventLoop to do his job!
            If the thread is the main/GUI Thread, you will also lock the hole GUI!

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            1 Reply Last reply
            0
            • J jsulm
              23 Jan 2020, 07:45

              @minju said in QML Progress Bar value not getting updated:

              The progress value is updated in an while loop

              That's the issue.
              Do not do such things in event driven applications an GUI thread!
              If you block the event loop with such an "update" loop events will not be executed (also such for GUI updates).
              How to solve your problem depends on the implementation of your C++ part which I don't know as you did not post the code and did not explain what exactly you're doing there.

              M Offline
              M Offline
              minju
              wrote on 23 Jan 2020, 09:29 last edited by
              #6

              @jsulm x
              The Sample C++code is below

              backend.cpp
              Backend::Backend {
              m_progress =0;
              }
              float Backend::progress{
              return m_progress;
              }
              void Backend::setprogress(const float & data)
              {
              if(data == m_progress)
              return;

              m_progress=data;

              emit progressChanged() ;
              }
              void Backend::startTxn() {
              for(int i=0;i<10;i++) {
              setprogress (.2);
              //some processing
              setprogress (.4);
              setprogress (.6);
              setprogress (1);

              }

              J K 2 Replies Last reply 23 Jan 2020, 09:56
              0
              • M minju
                23 Jan 2020, 09:29

                @jsulm x
                The Sample C++code is below

                backend.cpp
                Backend::Backend {
                m_progress =0;
                }
                float Backend::progress{
                return m_progress;
                }
                void Backend::setprogress(const float & data)
                {
                if(data == m_progress)
                return;

                m_progress=data;

                emit progressChanged() ;
                }
                void Backend::startTxn() {
                for(int i=0;i<10;i++) {
                setprogress (.2);
                //some processing
                setprogress (.4);
                setprogress (.6);
                setprogress (1);

                }

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 23 Jan 2020, 09:56 last edited by
                #7

                @minju You should rather use QTimer to send the updates regularly instead of event loop blocking loop.

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

                M 1 Reply Last reply 23 Jan 2020, 10:04
                2
                • J jsulm
                  23 Jan 2020, 09:56

                  @minju You should rather use QTimer to send the updates regularly instead of event loop blocking loop.

                  M Offline
                  M Offline
                  minju
                  wrote on 23 Jan 2020, 10:04 last edited by
                  #8

                  @jsulm
                  I tried timer it has the same issuse

                  J 1 Reply Last reply 23 Jan 2020, 10:07
                  0
                  • M minju
                    23 Jan 2020, 10:04

                    @jsulm
                    I tried timer it has the same issuse

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 23 Jan 2020, 10:07 last edited by
                    #9

                    @minju Please show your code with timer

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

                    1 Reply Last reply
                    0
                    • M minju
                      23 Jan 2020, 09:29

                      @jsulm x
                      The Sample C++code is below

                      backend.cpp
                      Backend::Backend {
                      m_progress =0;
                      }
                      float Backend::progress{
                      return m_progress;
                      }
                      void Backend::setprogress(const float & data)
                      {
                      if(data == m_progress)
                      return;

                      m_progress=data;

                      emit progressChanged() ;
                      }
                      void Backend::startTxn() {
                      for(int i=0;i<10;i++) {
                      setprogress (.2);
                      //some processing
                      setprogress (.4);
                      setprogress (.6);
                      setprogress (1);

                      }

                      K Offline
                      K Offline
                      KroMignon
                      wrote on 23 Jan 2020, 10:47 last edited by
                      #10

                      @minju said in QML Progress Bar value not getting updated:

                      void Backend::startTxn() {
                      for(int i=0;i<10;i++) {
                      setprogress (.2);
                      //some processing
                      setprogress (.4);
                      setprogress (.6);
                      setprogress (1);
                      }

                      This function will also lock the event loop of the QThread used by Backend.
                      You may try this:

                      #include <QAbstractEventDispatcher>
                      ...
                      void Backend::setprogress(const float & data)
                      {
                          if(data == m_progress)
                              return;
                      
                          m_progress=data;
                      
                          emit progressChanged() ;
                          this->thread()->eventDispatcher()->processEvents(QEventLoop::AllEvents);
                      }
                      

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      M 1 Reply Last reply 24 Jan 2020, 03:52
                      0
                      • K KroMignon
                        23 Jan 2020, 10:47

                        @minju said in QML Progress Bar value not getting updated:

                        void Backend::startTxn() {
                        for(int i=0;i<10;i++) {
                        setprogress (.2);
                        //some processing
                        setprogress (.4);
                        setprogress (.6);
                        setprogress (1);
                        }

                        This function will also lock the event loop of the QThread used by Backend.
                        You may try this:

                        #include <QAbstractEventDispatcher>
                        ...
                        void Backend::setprogress(const float & data)
                        {
                            if(data == m_progress)
                                return;
                        
                            m_progress=data;
                        
                            emit progressChanged() ;
                            this->thread()->eventDispatcher()->processEvents(QEventLoop::AllEvents);
                        }
                        
                        M Offline
                        M Offline
                        minju
                        wrote on 24 Jan 2020, 03:52 last edited by
                        #11

                        @KroMignon
                        I tried the event dispatcher the problem still exist. The progress bar only updates once

                        1 Reply Last reply
                        0

                        1/11

                        23 Jan 2020, 04:54

                        • Login

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