Solved High CPU usage on QWidget's update()
-
Hi, I'm trying to find out the source of a high CPU usage. I have already tried to comment out all code in the
paintEvent()
but it didn't helped. However the CPU usage dropped rapidly when I stopped calling theupdate()
function.Some facts about the device/app
- The app uses QWS
- it is a full screen app
Any idea how to optimize the code? What to check?
-
Hi,
How are you calling update and why ?
-
In our code we call update(QRect) multiple times to update each visualisation object.
How does exactly work the update(QRect) in respect to paintEvent()? In our code we call update(QRect) multiple times. Will the paintEvent be called also multiple times or only once with the overall region including all rectangles? -
Calls to update should schedule a paint event to happen so it should not trigger an immediate repaint. However I don't know how it can optimize this if you call update repeatedly with rectangles of different sizes.
-
@Radim, @SGaist
Paint events are (ordinarily) compressed (as with keyboard events), so multiple calls toupdate
generate a single paint event, provided the pending one was not consumed. Depending on the rect/region passed, the engine marks the first ancestral native widget's area as dirty and schedules a paint event. Ultimately, the dirty regions are united (geometrically) and a paint event is delivered when appropriate.@Radim,
If you're painting your widget with opaque colors and respect theQRegion
instance passed along with the paint event, you could most probably safely set either theQt::WA_NoSystemBackground
attribute, or depending on the case even theQt::WA_OpaquePaintEvent
attribute. This'd skip the background erasing done by Qt and you should be able to squeeze a bit more out of the widget. -
After some testing it seems the bottle neck is the video memory throughput.