[SOLVED] QWidget::repaint: Recursive repaint detected



  • I have a project which has multiple threads. Each thread has a "worker class" which updates a single progress bar located in the main thread (MainWindow).
    The progress bar's pointer is passed to the "worker class" at at the time it was instantiated. I didn't subclass QThread but instead, I used QObject::moveToThread() to pass the worker class to a thread.

    @
    QThread1 ---> QProgressBar1
    QThread2 ---> QProgressBar2
    QThread3 ---> QProgressBar3
    ....
    @

    when there are multiple threads/worker class created, "QWidget::repaint: Recursive repaint detected" error comes out.
    I am thinking that it was caused by passing the pointer of the progress bar to another thread.
    What is the solution for this? Thanks



  • You can not (directly) update widgets from within threads.

    I suspect you're using methods like setValue on the progress bar from within the threads, right? Don't do that. Instead, use a signal-slot connection. The setValue method is already a slot, so there is very little code overhead. The signal-slot mechanism will take care of making this updating thread save.



  • [quote author="Andre" date="1361176505"]You can not (directly) update widgets from within threads.

    I suspect you're using methods like setValue on the progress bar from within the threads, right? Don't do that. Instead, use a signal-slot connection. The setValue method is already a slot, so there is very little code overhead. The signal-slot mechanism will take care of making this updating thread save.[/quote]

    Yes, you are right. I will try to rewrite the code. Thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.