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. Setting value to QProgressBar causes program to crash
Forum Updated to NodeBB v4.3 + New Features

Setting value to QProgressBar causes program to crash

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 4 Posters 4.8k Views 2 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.
  • B bs55

    I designed a multithreaded video-recording program but it sometimes crashes and I need help to figure out why.

    My threads (which extends QThread) emit a signal (with an int identifying them and a double indicating their progress) which is connected to a slot in the MainWindow. The slot average the progress of the different threads and update a QProgressBar. I tried to catch the errors but it doesn't work...

    Code:

    void MainWindow::captureProgressHandler(int i_Thread, double d_Progress) {
            v_d_Progress[i_Thread] = d_Progress;
    
            double d_Average = 0.0;
            for (int i = 0; i < v_d_Progress.size(); i++) {
                d_Average += v_d_Progress[i];
            }
            d_Average /= v_d_Progress.size();
            d_Average *= 100;
    
            qInfo() << "Average progress:" << (int) d_Average << "%.";
    
            if (qpb_Progress->value() != (int) d_Average) {
                try {
                    qpb_Progress->setValue((int) d_Average);
                } catch (...) { // Does not work 
                    qInfo() << "Error!";
                }
            }
    }
    

    Error:

    QWidget::repaint: Recursive repaint detected
    The program has unexpectedly finished.
    
    T Offline
    T Offline
    Tirupathi Korla
    wrote on last edited by
    #4

    @bs55
    Are you sure your application is crashing in this function??

    B 1 Reply Last reply
    0
    • mrjjM mrjj

      Hi
      qpb_Progress is a member of MainWindow ?

      captureProgressHandler is the slot that all threads signal is connected to ?

      B Offline
      B Offline
      bs55
      wrote on last edited by
      #5

      @mrjj Yes qpb_Progress is a member of the MainWindow and captureProgressHandler(int i_Thread, double d_Progress) is the slot connected to the thread's signal.

      1 Reply Last reply
      0
      • T Tirupathi Korla

        @bs55
        Are you sure your application is crashing in this function??

        B Offline
        B Offline
        bs55
        wrote on last edited by
        #6

        @Tirupathi-Korla Yes because when I comment this line

        // qpb_Progress->setValue((int) d_Average); 
        

        the program doen not crash...

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

          Is qpb_Progress initialised properly ?

          Can you show the stack trace ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          B 1 Reply Last reply
          0
          • SGaistS SGaist

            Is qpb_Progress initialised properly ?

            Can you show the stack trace ?

            B Offline
            B Offline
            bs55
            wrote on last edited by
            #8

            @SGaist The QProgressBar is initialized by this line:

            qpb_Progress = new QProgressBar(this);
            

            The stack trace is as follows:

            Thread # 1 :  50 %.
            Thread # 0 :  50 %.
            QWidget::repaint: Recursive repaint detected
            Average progress: 25 %.
            The program has unexpectedly finished.
            The process was ended forcefully.
            /home/remi/Documents/Internship/MyProjects/build-SpinnakerSandboxQt3-Desktop-Debug/SpinnakerSandboxQt crashed.
            

            It does not occur when I use only one camera (and therefore one thread) so my guess is that the function is executed twice simutanously and that it causes a conflict when the two instance try to access the QProgressBar at the same time...

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

              Are you trying to update GUI elements directly your threads ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              B 1 Reply Last reply
              0
              • SGaistS SGaist

                Are you trying to update GUI elements directly your threads ?

                B Offline
                B Offline
                bs55
                wrote on last edited by
                #10

                @SGaist No the thread emit a signal that is connected to a slot in the MainWindow...

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  Hi
                  I tried with 2 worker objets to have them bombard a ProgressBar
                  in mainwindow but i couldn't get the same error.

                  B 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    Hi
                    I tried with 2 worker objets to have them bombard a ProgressBar
                    in mainwindow but i couldn't get the same error.

                    B Offline
                    B Offline
                    bs55
                    wrote on last edited by
                    #12

                    @mrjj Maybe the error only occurs on Linux.
                    Considering the number of cameras and their framerate it will be called up to 2440 times per second (that's one call every 0.41 milliseconds). Maybe Qt isn't up for the task...

                    mrjjM 1 Reply Last reply
                    0
                    • B bs55

                      @mrjj Maybe the error only occurs on Linux.
                      Considering the number of cameras and their framerate it will be called up to 2440 times per second (that's one call every 0.41 milliseconds). Maybe Qt isn't up for the task...

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @bs55
                      Hi
                      hard to say as im not sure what give the
                      "Recursive repaint detected"
                      it does sound like a paint is in progress while new one started but
                      signals should prevent that. ( i tried with 6 threads but still no error)

                      Qt uses native tasks so if its not fast enough, you might need other design to reach such speeds.

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

                        You do realise that most screens have at most a 60fps refresh rate while the human eyes is already fooled at 24 ? So having a 2440 Hz refresh rate is useless and from the looks of it you are even overloading your application with that.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        B 1 Reply Last reply
                        1
                        • SGaistS SGaist

                          You do realise that most screens have at most a 60fps refresh rate while the human eyes is already fooled at 24 ? So having a 2440 Hz refresh rate is useless and from the looks of it you are even overloading your application with that.

                          B Offline
                          B Offline
                          bs55
                          wrote on last edited by
                          #15

                          @SGaist You're right, the function to register the progress of each threads will be called 2440 times per second but I should create another function just to refresh the progress bar that would be called less often...

                          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