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

QProgressBar

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 4 Posters 1.6k 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.
  • J Offline
    J Offline
    jagl
    wrote on last edited by jagl
    #1

    hi i want to make a Progressbar, when i press the button it starts and when the task ends it arrives at 100% i tested this code but it does not work :

    void tu::on_Lidar_clicked()
    {

            QProgressBar pBAR ;
            QFutureWatcher<void>Watcher1;
            Watcher1.setFuture(QtConcurrent::run(T1));
            QFutureWatcher<void>Watcher;
            Watcher.setFuture(QtConcurrent::run(T2));
    
            connect (&pBAR, SIGNAL(canceled()), &Watcher, SLOT(cancel()));
            connect (&Watcher, SIGNAL(finished()),&pBAR , SLOT(reset()));
            connect (&Watcher, SIGNAL(progressRangeChanged(int,int)),&pBAR , SLOT(setRange(int,int)));
            connect (&Watcher, SIGNAL(progressValueChanged(int,int)),&pBAR , SLOT(setValue(int)));
    

    }
    Any help please

    jsulmJ 1 Reply Last reply
    0
    • J jagl

      hi i want to make a Progressbar, when i press the button it starts and when the task ends it arrives at 100% i tested this code but it does not work :

      void tu::on_Lidar_clicked()
      {

              QProgressBar pBAR ;
              QFutureWatcher<void>Watcher1;
              Watcher1.setFuture(QtConcurrent::run(T1));
              QFutureWatcher<void>Watcher;
              Watcher.setFuture(QtConcurrent::run(T2));
      
              connect (&pBAR, SIGNAL(canceled()), &Watcher, SLOT(cancel()));
              connect (&Watcher, SIGNAL(finished()),&pBAR , SLOT(reset()));
              connect (&Watcher, SIGNAL(progressRangeChanged(int,int)),&pBAR , SLOT(setRange(int,int)));
              connect (&Watcher, SIGNAL(progressValueChanged(int,int)),&pBAR , SLOT(setValue(int)));
      

      }
      Any help please

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

      @jagl said in QProgressBar:

      QProgressBar pBAR ;

      Your progress bar is a local variable which is destroyed as soon as on_Lidar_clicked() finishes. Also your watcher are local variables.
      Make all these variables class members.

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

      J 1 Reply Last reply
      1
      • jsulmJ jsulm

        @jagl said in QProgressBar:

        QProgressBar pBAR ;

        Your progress bar is a local variable which is destroyed as soon as on_Lidar_clicked() finishes. Also your watcher are local variables.
        Make all these variables class members.

        J Offline
        J Offline
        jagl
        wrote on last edited by
        #3

        @jsulm thanks for your replay
        i did :
        in the file .h:
        public:
        QProgressBar pBAR ;
        QFutureWatcher<void> Watcher1;
        QFutureWatcher<void>Watcher;
        in the file .cpp:

               Watcher1.setFuture(QtConcurrent::run(T1));
                Watcher.setFuture(QtConcurrent::run(T2));
        
                connect (&pBAR, SIGNAL(canceled()), &Watcher, SLOT(cancel()));
                connect (&Watcher, SIGNAL(finished()),&pBAR , SLOT(reset()));
                connect (&Watcher, SIGNAL(progressRangeChanged(int,int)),&pBAR , SLOT(setRange(int,int)));
                connect (&Watcher, SIGNAL(progressValueChanged(int,int)),&pBAR , SLOT(setValue(int)));
        

        }
        But it didn't work

        jsulmJ 1 Reply Last reply
        0
        • J jagl

          @jsulm thanks for your replay
          i did :
          in the file .h:
          public:
          QProgressBar pBAR ;
          QFutureWatcher<void> Watcher1;
          QFutureWatcher<void>Watcher;
          in the file .cpp:

                 Watcher1.setFuture(QtConcurrent::run(T1));
                  Watcher.setFuture(QtConcurrent::run(T2));
          
                  connect (&pBAR, SIGNAL(canceled()), &Watcher, SLOT(cancel()));
                  connect (&Watcher, SIGNAL(finished()),&pBAR , SLOT(reset()));
                  connect (&Watcher, SIGNAL(progressRangeChanged(int,int)),&pBAR , SLOT(setRange(int,int)));
                  connect (&Watcher, SIGNAL(progressValueChanged(int,int)),&pBAR , SLOT(setValue(int)));
          

          }
          But it didn't work

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

          @jagl I don't think you can use progressValueChanged() signal with https://doc.qt.io/qt-5/qtconcurrent.html#run (see the description there). How would it know how far your calculations are? You will need to go for a worker object which is executed in a thread and emits a signal to pass current progress to the outside world. See https://doc.qt.io/qt-5/qthread.html

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

          J 1 Reply Last reply
          0
          • jsulmJ jsulm

            @jagl I don't think you can use progressValueChanged() signal with https://doc.qt.io/qt-5/qtconcurrent.html#run (see the description there). How would it know how far your calculations are? You will need to go for a worker object which is executed in a thread and emits a signal to pass current progress to the outside world. See https://doc.qt.io/qt-5/qthread.html

            J Offline
            J Offline
            jagl
            wrote on last edited by
            #5

            @jsulm ok I will see thanks however I have another question please I would like when I click on the lidar button, the camera_capture button will be clicked will do that but it didn't work :
            connect (ui->Lidar, SIGNAL(clicked()), ui->Capture_Camera, SLOT(clicked()));
            any idea please

            jsulmJ 1 Reply Last reply
            0
            • J jagl

              @jsulm ok I will see thanks however I have another question please I would like when I click on the lidar button, the camera_capture button will be clicked will do that but it didn't work :
              connect (ui->Lidar, SIGNAL(clicked()), ui->Capture_Camera, SLOT(clicked()));
              any idea please

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

              @jagl said in QProgressBar:

              SLOT(clicked()

              clicked is a signal, so change SLOT to SIGNAL

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

              J 1 Reply Last reply
              0
              • jsulmJ jsulm

                @jagl said in QProgressBar:

                SLOT(clicked()

                clicked is a signal, so change SLOT to SIGNAL

                J Offline
                J Offline
                jagl
                wrote on last edited by jagl
                #7

                @jsulm
                thank you it works.
                for the problem of QProgressBar I changed the programming but the progressbar is at 100% before the termination of Watcher1 and Watcher
                code
                .h:
                public:
                QTimer *m_timer;
                QFutureWatcher<void>Watcher1;
                QFutureWatcher<void>Watcher;
                private slots:
                void slotProcessBar();

                .cpp:
                m_timer = new QTimer(this);
                ui->progressBar->setRange(0, 99);
                ui->progressBar->setValue(0);

                    connect (ui->progressBar, SIGNAL(canceled()), &Watcher, SLOT(cancel()));
                    connect (&Watcher, SIGNAL(finished()),ui->progressBar, SLOT(reset()));
                    connect(m_timer, SIGNAL(timeout()), this, SLOT(slotProcessBar()));
                

                void tu::slotProcessBar()
                {
                static int pos = 0;
                if (pos == 100)
                {
                m_timer->stop();
                return;
                }

                 ui->progressBar->setValue(pos++);
                

                }
                void tu::on_Lidar_clicked()
                {

                         m_timer->start();
                        Watcher1.setFuture(QtConcurrent::run(tu1));
                        Watcher.setFuture(QtConcurrent::run(tu2));
                

                }
                can you help me please

                jsulmJ 1 Reply Last reply
                0
                • J jagl

                  @jsulm
                  thank you it works.
                  for the problem of QProgressBar I changed the programming but the progressbar is at 100% before the termination of Watcher1 and Watcher
                  code
                  .h:
                  public:
                  QTimer *m_timer;
                  QFutureWatcher<void>Watcher1;
                  QFutureWatcher<void>Watcher;
                  private slots:
                  void slotProcessBar();

                  .cpp:
                  m_timer = new QTimer(this);
                  ui->progressBar->setRange(0, 99);
                  ui->progressBar->setValue(0);

                      connect (ui->progressBar, SIGNAL(canceled()), &Watcher, SLOT(cancel()));
                      connect (&Watcher, SIGNAL(finished()),ui->progressBar, SLOT(reset()));
                      connect(m_timer, SIGNAL(timeout()), this, SLOT(slotProcessBar()));
                  

                  void tu::slotProcessBar()
                  {
                  static int pos = 0;
                  if (pos == 100)
                  {
                  m_timer->stop();
                  return;
                  }

                   ui->progressBar->setValue(pos++);
                  

                  }
                  void tu::on_Lidar_clicked()
                  {

                           m_timer->start();
                          Watcher1.setFuture(QtConcurrent::run(tu1));
                          Watcher.setFuture(QtConcurrent::run(tu2));
                  

                  }
                  can you help me please

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

                  @jagl You're not setting timer interval as far as I can see (https://doc.qt.io/qt-5/qtimer.html#interval-prop)

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

                  J 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @jagl You're not setting timer interval as far as I can see (https://doc.qt.io/qt-5/qtimer.html#interval-prop)

                    J Offline
                    J Offline
                    jagl
                    wrote on last edited by
                    #9

                    @jsulm the timer will start when I click on lidar and will end when the Watcher1 and Watcher ends

                    jsulmJ 1 Reply Last reply
                    0
                    • J jagl

                      @jsulm the timer will start when I click on lidar and will end when the Watcher1 and Watcher ends

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

                      @jagl It is clear when the timer will start.
                      What I'm talking about is the timer interval.
                      If you read the link I posted you will see: "A QTimer with a timeout interval of 0 will time out as soon as all the events in the window system's event queue have been processed.". So, you will get the timeouts very fast and your progress bar will also reach very fast 100%.
                      But, I don't understand why you invented a timer here? It will only work if you know in advance how long your back ground task will run. But you don't, right?

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

                      J 4 Replies Last reply
                      0
                      • jsulmJ jsulm

                        @jagl It is clear when the timer will start.
                        What I'm talking about is the timer interval.
                        If you read the link I posted you will see: "A QTimer with a timeout interval of 0 will time out as soon as all the events in the window system's event queue have been processed.". So, you will get the timeouts very fast and your progress bar will also reach very fast 100%.
                        But, I don't understand why you invented a timer here? It will only work if you know in advance how long your back ground task will run. But you don't, right?

                        J Offline
                        J Offline
                        jagl
                        wrote on last edited by
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @jagl It is clear when the timer will start.
                          What I'm talking about is the timer interval.
                          If you read the link I posted you will see: "A QTimer with a timeout interval of 0 will time out as soon as all the events in the window system's event queue have been processed.". So, you will get the timeouts very fast and your progress bar will also reach very fast 100%.
                          But, I don't understand why you invented a timer here? It will only work if you know in advance how long your back ground task will run. But you don't, right?

                          J Offline
                          J Offline
                          jagl
                          wrote on last edited by
                          #12
                          This post is deleted!
                          1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @jagl It is clear when the timer will start.
                            What I'm talking about is the timer interval.
                            If you read the link I posted you will see: "A QTimer with a timeout interval of 0 will time out as soon as all the events in the window system's event queue have been processed.". So, you will get the timeouts very fast and your progress bar will also reach very fast 100%.
                            But, I don't understand why you invented a timer here? It will only work if you know in advance how long your back ground task will run. But you don't, right?

                            J Offline
                            J Offline
                            jagl
                            wrote on last edited by
                            #13
                            This post is deleted!
                            1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @jagl It is clear when the timer will start.
                              What I'm talking about is the timer interval.
                              If you read the link I posted you will see: "A QTimer with a timeout interval of 0 will time out as soon as all the events in the window system's event queue have been processed.". So, you will get the timeouts very fast and your progress bar will also reach very fast 100%.
                              But, I don't understand why you invented a timer here? It will only work if you know in advance how long your back ground task will run. But you don't, right?

                              J Offline
                              J Offline
                              jagl
                              wrote on last edited by
                              #14

                              @jsulm Please now the ProgressBar works but it does not reset
                              connect (&Watcher1, SIGNAL(progressRangeChanged(int,int)),ui->progressBar, SLOT(setRange(int,int)));
                              connect (&Watcher1, SIGNAL(progressValueChanged(int,int)),ui->progressBar, SLOT(setValue(int)));
                              connect (&Watcher, SIGNAL(finished()),ui->progressBar , SLOT(reset()));

                              1 Reply Last reply
                              0
                              • J Offline
                                J Offline
                                jagl
                                wrote on last edited by
                                #15

                                connect (&Watcher1, SIGNAL(progressRangeChanged(int,int)),ui->progressBar, SLOT(setRange(int,int)));
                                connect (&Watcher1, SIGNAL(progressValueChanged(int,int)),ui->progressBar, SLOT(setValue(int)));
                                connect (&Watcher, SIGNAL(finished()), this, SLOT(slotProcessBar()));
                                void Rover::slotProcessBar()
                                {

                                      ui-> progressBar->setMaximum(1);
                                       ui->progressBar->reset();
                                

                                }

                                KroMignonK JonBJ 2 Replies Last reply
                                0
                                • J jagl

                                  connect (&Watcher1, SIGNAL(progressRangeChanged(int,int)),ui->progressBar, SLOT(setRange(int,int)));
                                  connect (&Watcher1, SIGNAL(progressValueChanged(int,int)),ui->progressBar, SLOT(setValue(int)));
                                  connect (&Watcher, SIGNAL(finished()), this, SLOT(slotProcessBar()));
                                  void Rover::slotProcessBar()
                                  {

                                        ui-> progressBar->setMaximum(1);
                                         ui->progressBar->reset();
                                  

                                  }

                                  KroMignonK Offline
                                  KroMignonK Offline
                                  KroMignon
                                  wrote on last edited by
                                  #16

                                  @jagl said in QProgressBar:

                                  connect (&Watcher1, SIGNAL(progressRangeChanged(int,int)),ui->progressBar, SLOT(setRange(int,int)));
                                  connect (&Watcher1, SIGNAL(progressValueChanged(int,int)),ui->progressBar, SLOT(setValue(int)));
                                  connect (&Watcher, SIGNAL(finished()), this, SLOT(slotProcessBar()));

                                  I am pretty sure that those connect do not work.
                                  As far as I can see, Watcher1 is defined as QFutureWatcher<void> Watcher1;
                                  and Watcher as QFutureWatcher<void>Watcher;

                                  So there is no signal progressRangeChanged(int,int) available... so how should this work?

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

                                  J 1 Reply Last reply
                                  2
                                  • J jagl

                                    connect (&Watcher1, SIGNAL(progressRangeChanged(int,int)),ui->progressBar, SLOT(setRange(int,int)));
                                    connect (&Watcher1, SIGNAL(progressValueChanged(int,int)),ui->progressBar, SLOT(setValue(int)));
                                    connect (&Watcher, SIGNAL(finished()), this, SLOT(slotProcessBar()));
                                    void Rover::slotProcessBar()
                                    {

                                          ui-> progressBar->setMaximum(1);
                                           ui->progressBar->reset();
                                    

                                    }

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

                                    @jagl
                                    Aren't you asking just the same question/problem in https://forum.qt.io/topic/128560/set-qlabel-from-another-thread/ ?

                                    As we asked you there, if you would please take the time to change over to the New Signal Slot Syntax you would save us & yourself a lot of time on what looks like incorrect connect()s.

                                    1 Reply Last reply
                                    0
                                    • KroMignonK KroMignon

                                      @jagl said in QProgressBar:

                                      connect (&Watcher1, SIGNAL(progressRangeChanged(int,int)),ui->progressBar, SLOT(setRange(int,int)));
                                      connect (&Watcher1, SIGNAL(progressValueChanged(int,int)),ui->progressBar, SLOT(setValue(int)));
                                      connect (&Watcher, SIGNAL(finished()), this, SLOT(slotProcessBar()));

                                      I am pretty sure that those connect do not work.
                                      As far as I can see, Watcher1 is defined as QFutureWatcher<void> Watcher1;
                                      and Watcher as QFutureWatcher<void>Watcher;

                                      So there is no signal progressRangeChanged(int,int) available... so how should this work?

                                      J Offline
                                      J Offline
                                      jagl
                                      wrote on last edited by
                                      #18

                                      @KroMignon thank you for your reply but why she work ?

                                      KroMignonK 1 Reply Last reply
                                      0
                                      • J jagl

                                        @KroMignon thank you for your reply but why she work ?

                                        KroMignonK Offline
                                        KroMignonK Offline
                                        KroMignon
                                        wrote on last edited by
                                        #19

                                        @jagl said in QProgressBar:

                                        thank you for your reply but why she work ?

                                        This do NOT work!

                                        I know that C++ is not a language which is easy to learn, but it is mandatory to learn it before trying to create application with Qt.

                                        It is also strongly recommended to read documentation.
                                        It is Okay not to understand all the stuff. In this case you can ask what you do not understand.

                                        Do you have read QFutureWatcher documentation?
                                        https://doc.qt.io/qt-5/qfuturewatcher.html#details

                                        QFutureWatcher is a template class to simplify QFuture monitoring.
                                        So you can be informed when the QFuture is finished.

                                        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

                                        • Login

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