Momergil
Momergil

Reputation: 2281

QWidget paintEvent stop being called without reason

I'm finding a very strange situation while updating a QWidget in one of my Qt applications. What happens is that suddenly the widget's paintEvent(QEvent*) stops being called when the widget->update() method is called without any warning or command.

My application, working in Embedded Linux with Qt 4.8.5 for ARM, has two (relevant) threads: one gets data from a socket connection, fills a buffer with it and calls a slot in a distant object asking it to update the plot widget (with the update() function). The other thread is the main thread responsible for widget paintings (a rule in Qt) which execute the void paintEvent(QEvent*) function. So the sequence of events is:

  1. Reading thread get and identify a data pack
  2. Reading thread put the data inside a buffer (a QAbstractTableModel derived class)
  3. In the same function, reading thread emits a signal with Qt::DirectConnection to a UI base widget which has the plotting widget as its child. The receiver slot is called slotPQDataChanged.
  4. slotPQDataChanged calls the child widget's update function: poSubWidget->update();
  5. In the main thread, at the moment Qt "wishes", the poSubWidget's paintEvent(QEvent*) function is called. It has a QPainter inside which draws the received data on it.

This process happens something like 5 times per second. When I start the system, everything runs fine for some time (5-10 minutes normally), but then suddenly the update of poSubWidget stop happening. I know for certain that it's not the reading thread that stoped because, thanks to a call to qDebug(), I know that "slotPQDataChanged" continues to be called. I know as well that it's not the main thread that was killed or something like that because a timer on the screen continues to work fine when the problem happens. And I know there is no point in my code where I ask the child widget not to update when update() is called.

And, of course, I have no idea whatsoever what is happening; a (quick) research on SO returned no positive results.

It's worth mentioning that my application is probably with a bug that is making it be killed sometimes because of "out of memory".

So, any suggestions on what could be happening?

Upvotes: 4

Views: 1043

Answers (2)

AlexDarkVoid
AlexDarkVoid

Reputation: 542

Had the same problem in my video playback program - paintEvent() stopped being called after ~5min. Solved this by moving update() call from a separate thread into one of widget's slots (invoked via a signal). So make sure you call update from within QT's event thread.

Upvotes: 1

fbucek
fbucek

Reputation: 1667

1) Solve "out of memory" problem first. It can easily be source of the problem.

2) Connecting Thread to GUI using Qt::DirectConnection is not a good idea unless you know exactly what you are doing. ( It also can be source of the problems ) Thread and gui should be connected using Qt::QueuedConnection

Upvotes: 3

Related Questions