frans
frans

Reputation: 9758

Qt: force UI update in the main thread

I'm writing an image viewer and I want to pre-load the next image after displaying the current one.

The problem is now: When I display an image (e.g. by applying a QPixmap to a QLabel) and load the next image in the same Qt-method-call (e.g. in the same function) the image will be displayed after the pre-loading. So I still have the time gap..

I could switch to a threaded solution but this would introduce a lot of more problems.

So my question for now is: Can I force Qt to update()/redraw() the UI in the current call stack or will I have to find a way to do the pre-loading in another "metacall"?

Upvotes: 1

Views: 274

Answers (1)

vahancho
vahancho

Reputation: 21220

I would try to solve the problem in the following way (without dealing with threads):

void setCurrentImage()
{
    [..]
    label->setPixmap(pixmap);
    QTimer::singleShot(0, this, SLOT(preloadNextImage()));
    [..]
}

// A slot.
void preloadNextImage()
{
    // Do preload.
}

Upvotes: 1

Related Questions