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. QWidget::repaint: Recursive repaint detected

QWidget::repaint: Recursive repaint detected

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 4.5k 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.
  • X Offline
    X Offline
    Xav12358
    wrote on last edited by
    #1

    Hello,

    I use a QWidget in a Qthread and I had to modify the image in a Qlabel of multiple object.
    The problem is when I modify the image inside the Qlabel the update of image works bad.

    I ha to use repaint fonction to force th label to update regulary the display. But most of the time I have this error:

    QWidget::repaint: Recursive repaint detected
    
    

    How Can I force a update of the label without create a recursive repaint?

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

      Hi,

      One thing that is wrong here: updating widgets outside the GUI thread is a no go.

      What exactly are you doing ?

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

      X 1 Reply Last reply
      3
      • SGaistS SGaist

        Hi,

        One thing that is wrong here: updating widgets outside the GUI thread is a no go.

        What exactly are you doing ?

        X Offline
        X Offline
        Xav12358
        wrote on last edited by
        #3

        @SGaist In fact I have a blocking process, this is the reason why I must put a partof my process in a Qthread.
        That Qthread process had to update a list a Qlabel image and display it. The problem if I don't use repaint event the label doesn't refresh dynamically, it waits the last image to update its content.

        So I use repaint and to avoid a recursive repaint error I made that:

            void paintEvent(QPaintEvent *event)
            {
                qDebug() << "GLWidget::paintEvent In";
                if(!paintingActive())
                    QWidget::paintEvent(event);
                qDebug() << "GLWidget::paintEvent Out";
            }
        

        But it don't seems to work, I still have the same error.

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

          Again: don't do GUI changes to widgets from other threads

          Use signals and slots to update your labels, you may need a class like QSignalMapper. Depending on how you get/generate the images, the Mandelbrot example would likely be useful.

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

          1 Reply Last reply
          2
          • X Offline
            X Offline
            Xav12358
            wrote on last edited by
            #5

            Is it possible to have a QSignalMapper like this:

            My QThread send a signal (emit newImage(QImage,int) connect to my object ImageWidget (slot(void newImage(Qimage)) ?
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Did you read the class documentation ? It doesn't work like that.

              Anyway, can you describe more precisely your setup ?

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

              1 Reply Last reply
              0
              • X Offline
                X Offline
                Xav12358
                wrote on last edited by Xav12358
                #7

                How should I emit a signal from a QThread?

                Here is the code I use:

                class BGEPreviewWorker : public QObject
                {
                    QHash<QString,GLWidget*> hashWidgetView; ///< list of display data
                
                    Q_OBJECT
                    int iwidth_;            ///< memorise the with of element to process
                    int iheight_;           ///< memorise the height of element to process
                
                    cv::Mat dx1_blur1;
                    double min,max;
                
                
                    QHash<QString,GLWidget*> hashWidgetView; ///< list of display data
                public:
                
                    BGEPreviewWorker(QObject *parent = NULL);
                    ~BGEPreviewWorker();
                
                    ///
                    /// \brief display function which collct all data in the gpu and display it
                    ///
                    void display();
                
                
                
                public slots:
                    void work();
                    void askToClosed(QString);
                
                signals:
                };
                
                
                BGEPreviewWorker::BGEPreviewWorker(QObject *parent):
                    QObject(parent),
                    iwidth_(1920),
                    iheight_(1080),
                    bIsRunning_(false),
                    bIsInitialised_(false)
                {
                
                
                
                
                    dx1_blur1.create(iheight_,iwidth_,CV_64F);
                
                    hashWidgetView["save_Blur1"]        = new GLWidget(iwidth_,iheight_,GLWidget::BGE_64F,0);
                
                
                
                    QHash<QString,GLWidget*>::iterator iter = hashWidgetView.begin();
                    for(int i = 0;
                        i<hashWidgetView.size();
                        i++)
                    {
                        connect(this,SIGNAL(newImage(ImageUpdater)),((iter+i)).value(),SLOT(newImage(ImageUpdater)));
                        
                
                
                        (iter+i).value()->show()
                
                    }
                
                }
                

                BGEPreviewWorker emit a signal (newImage) to the corresponding GLWirdget.
                Here how I use BGEPreviewWorker:

                  BGEPreviewWorker *BGEWork = new BGEPreviewWorker();
                   QThread*  BGEThread = new QThread();
                    BGEWork->moveToThread(BGEThread);
                
                    connect(BGEThread, SIGNAL(started()), BGEWork, SLOT(work()) );
                
                
                jsulmJ 1 Reply Last reply
                0
                • X Xav12358

                  How should I emit a signal from a QThread?

                  Here is the code I use:

                  class BGEPreviewWorker : public QObject
                  {
                      QHash<QString,GLWidget*> hashWidgetView; ///< list of display data
                  
                      Q_OBJECT
                      int iwidth_;            ///< memorise the with of element to process
                      int iheight_;           ///< memorise the height of element to process
                  
                      cv::Mat dx1_blur1;
                      double min,max;
                  
                  
                      QHash<QString,GLWidget*> hashWidgetView; ///< list of display data
                  public:
                  
                      BGEPreviewWorker(QObject *parent = NULL);
                      ~BGEPreviewWorker();
                  
                      ///
                      /// \brief display function which collct all data in the gpu and display it
                      ///
                      void display();
                  
                  
                  
                  public slots:
                      void work();
                      void askToClosed(QString);
                  
                  signals:
                  };
                  
                  
                  BGEPreviewWorker::BGEPreviewWorker(QObject *parent):
                      QObject(parent),
                      iwidth_(1920),
                      iheight_(1080),
                      bIsRunning_(false),
                      bIsInitialised_(false)
                  {
                  
                  
                  
                  
                      dx1_blur1.create(iheight_,iwidth_,CV_64F);
                  
                      hashWidgetView["save_Blur1"]        = new GLWidget(iwidth_,iheight_,GLWidget::BGE_64F,0);
                  
                  
                  
                      QHash<QString,GLWidget*>::iterator iter = hashWidgetView.begin();
                      for(int i = 0;
                          i<hashWidgetView.size();
                          i++)
                      {
                          connect(this,SIGNAL(newImage(ImageUpdater)),((iter+i)).value(),SLOT(newImage(ImageUpdater)));
                          
                  
                  
                          (iter+i).value()->show()
                  
                      }
                  
                  }
                  

                  BGEPreviewWorker emit a signal (newImage) to the corresponding GLWirdget.
                  Here how I use BGEPreviewWorker:

                    BGEPreviewWorker *BGEWork = new BGEPreviewWorker();
                     QThread*  BGEThread = new QThread();
                      BGEWork->moveToThread(BGEThread);
                  
                      connect(BGEThread, SIGNAL(started()), BGEWork, SLOT(work()) );
                  
                  
                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Xav12358 It doesn't matter whether you're in another thread or not: emitting signal is always same:

                  emit mySignal();
                  

                  Just use QueuedConnection when connecting signal and slot.

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

                  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