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

Bradley Smith bradley at baysmith.com
Wed Oct 21 07:48:35 CEST 2009


>
> No, it is not a deadlock. update() add an event in the process event list of
> Qt so update() do not directly call paintEvent() as I understand the
> documentation of Qt.

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."

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



More information about the Qt-interest-old mailing list