View Full Version : Using QWidget::update() from non-GUI thread

21st June 2011, 07:58
Sometimes my application crashes in QWidget::update() that is performing in non-GUI thread.

I am developing an application in which receives video frames from remote host and display them on QWidget.

For this purpose I use libVLC library that gives to me a decoded image. I receive image in libVLC callback, that is performing in separate libVLC thread. In this callback I'm trying to perform QWidget::update() method. Sometimes application crashes, and callstack is somewhere in this method. Here is the my callback code:

void VideoWidget::displayCB(void* picture)
QImage* image = reinterpret_cast<QImage*>(picture);

onScreenPixmap_ = QImage(*image);

delete image;

I know that GUI operations outside the main thread are not allowed in Qt. But according documentation QWidget::update() just schedules a paint event for processing when Qt returns to the main event loop and does not cause an immediate repaint.

The questtion is: is the rule "GUI operations outside the main thread are not allowed" appliable for QWidget::update()? Does this operation belongs to "GUI operations"?

21st June 2011, 08:10
QWidget::update() is not the culprit here. I think your code in some thread is trying to work on a datastructure which has been deleted.

Santosh Reddy
21st June 2011, 08:36
You cannot directly call QWidget::update() from Non-GUI thread. One way is to emit a signal from Non-GUI thread and connect it QWidget::update() slot for the required widget

21st June 2011, 10:11
Thank you.
I've connected signal from Non-GUI thread to slot QWidget::update() , and crash does not reproduce.