[Qt-interest] Widget does not update content after some time

Damien R damien.rg+news at gmail.com
Thu Oct 22 11:12:12 CEST 2009


Bradley Smith wrote:
> Although update() may not cause an immediate paint, it is not
> documented to be thread-safe, which means that it is probably only
> reentrant. Since the "Thread Support in Qt" page states "Classes in
> the documentation will be documented as thread-safe only if they are
> intended to be used by multiple threads."

I agree with you, I misinterpreted the documentation of update.

> Thread-safe communication can be accomplished by using queued signals.
> For example,
> 
> // Define a signal and slot
>     Q_OBJECT
> 
>     signals:
>         void signalUpdate();
> 
>     public slots:
>         void updateSlot() {
>             update();
>         }
> 
> // Connect the signal and slot as a queued connection
>     connect(this, SIGNAL(signalUpdate()), this, SLOT(updateSlot()),
> Qt::QueuedConnection);
> 
> // Send signal rather than call update() in setImage()
>     //update();
>     signalUpdate();
> 
> 
>   Bradley
Yes, and it is not necessary to create an updateSlot because update is
already a slot. connect should use Qt::QueuedConnection automatically
but I set it to Qt::QueuedConnection.

I need to do more test to be sure it's works.

PS: Sorry for multipost ...



More information about the Qt-interest-old mailing list