Qt 5 on Mac Uses a Ton of CPU
-
Environment:
Mac 0S X 10.8.2
Xcode 4.4.1 (although I do everything in QtCreator)
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)So I built a small video display app on 4.8 and it works fine. When there's no video displaying, it uses about 0.3% of the CPU and during video display it uses about 7% CPU. However, when I build that same app using Qt 5.0, it uses about 80% of the CPU when the app is not doing anything and about 86% when displaying a video.
The app displays video frames on a QLabel by calling setPixmap() on the QLabel. The problem appears to be that every call to setPixmap() triggers an update to the widget's backing store, which seems to trigger a paintEvent. So, it gets into an endless loop. If I don't call setPixmap() on the QLabel, it doesn't get into the loop... Of course, my video doesn't display either.
Here's the stack trace:
0 MainWindow::paintEvent mainwindow.cpp 84 0x1000050e0
1 QWidget::event 0x100e35a0b
2 QMainWindow::event 0x100f2636c
3 QApplicationPrivate::notify_helper 0x100dfeebe
4 QApplication::notify 0x100e002d0
5 QCoreApplication::notifyInternal 0x10199d0ae
6 QWidgetPrivate::drawWidget 0x100e3084f
7 QWidgetBackingStore::sync 0x100e0a380
8 QWidgetPrivate::syncBackingStore 0x100e285d7
9 QWidget::event 0x100e3601b
10 QMainWindow::event 0x100f2636c
11 QApplicationPrivate::notify_helper 0x100dfeebe
12 QApplication::notify 0x100e002d0
13 QCoreApplicationPrivate::sendPostedEvents 0x10199dc84
14 QWindowSystemInterface::sendWindowSystemEvents 0x1014086c1
15 QCocoaEventDispatcherPrivate::processPostedEvents 0x102e20e25
16 QCocoaEventDispatcherPrivate::postedEventsSourceCallback 0x102e2172b
17 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION 0x7fff90ff6101
18 __CFRunLoopDoSources0 0x7fff90ff5a25
19 __CFRunLoopRun 0x7fff91018dc5
20 CFRunLoopRunSpecific 0x7fff910186b2
... <More>