View Full Version : QEventLoop block...asleep?

8th October 2015, 15:34
Hallo Everybody!
I'm experiencing with a sneaky bug of my Qt application.

Briefly, in my application there's a QWidget drawing a plot: its name is MyPlotWidget and it's child of one child of QMainWindow's instance.
MyPlotWidget's refresh is triggered by a signal coming from a worker thread and connected to MyPlotWidget::refresh_slot():

QApplication::processEvents(); // This code line was added trying to fix the bug, but unsuccessfully

MyPlotWidget has a redefined MyPlotWidget::paintEvent(QPaintEvent *) which execution takes about 30-40ms.
The refresh triggering signal is emitted every 200ms.

The problem is that after a while (minutes) the system gets frozen: MyPlotWidget::refresh_slot() is called regularly every 200ms, update() is also called, but no paintEvent!!!
In another widget, "brother" of MyPlotWidget, there's a textual clock, which refresh is triggered by a QTimer: it gets frozen too.
The freeze condition is reversible: it's enough to touch the screen and trigger a layout change with resulting graphical refresh.

It's like the processing of the eventLoop is blocked. Possible?

Reading the documentaion, i see that the QEventLoop class has a wakeUp method...how should it be used? And why?
Why the eventLoop should be awaken?
How could I become aware that the QEventLoop is asleep?

Help appreciated, thank you very much!

8th October 2015, 16:29
Since the timer stops, it is likely that event processing is not done anymore.

Check if your slots actually return and do not sleep() or stay in a loop.,etc.


8th October 2015, 17:53
Yes anda_skoa, my slot returns and doesn't get in a loop.
The worker thread is operative, whereas the GUI seems to be frozed, but nevertheless responsive.

9th October 2015, 09:44
Hallo, i collected an element more.

The system doesn't get frozen if the QMainWindow GUI is refreshed.
The system has worked well without freezing for hours with a blinking label on the QMainWindow (to warn the user about a certain condition).
It seems that keeping the QMainWindow awake, the system keeps alert too...

9th October 2015, 14:39
It's plausible that I fixed the bug.

I discovered that MyPlotWidget wasn't related to the QMainWindow: due to a missing parent parameter, the relationship between the two was broken.
Activating the correct parent parameter transition, the system is going without freezing since more than 2 hours!!