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 Updated to NodeBB v4.3 + New Features

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 minju

    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

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on 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
    1
    • jsulmJ jsulm

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

      jsulmJ KroMignonK 2 Replies Last reply
      0
      • M minju

        @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

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on 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
        0
        • M minju

          @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

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on 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
          • jsulmJ jsulm

            @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 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);

            }

            jsulmJ KroMignonK 2 Replies Last reply
            0
            • M minju

              @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);

              }

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on 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
              2
              • jsulmJ jsulm

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

                M Offline
                M Offline
                minju
                wrote on last edited by
                #8

                @jsulm
                I tried timer it has the same issuse

                jsulmJ 1 Reply Last reply
                0
                • M minju

                  @jsulm
                  I tried timer it has the same issuse

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 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

                    @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);

                    }

                    KroMignonK Offline
                    KroMignonK Offline
                    KroMignon
                    wrote on 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
                    0
                    • KroMignonK KroMignon

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

                      • Login

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