Avoid warnings when fetching file icons without a CGContextRef

This can happen when instantiating a QFileIconProvider and no suitable
graphics context is available (e.g., when only using a QQuickView).

The proper, longer (5.2) term solution would be to have the platform theme
return a QIcon with a NSImage icon provider.

Task-number: QTBUG-31908
Change-Id: Ibfdb51e0a7dd2c33761a463f4eb6619f0aca19f0
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
bb10
Gabriel de Dietrich 2013-07-02 15:21:07 +02:00 committed by The Qt Project
parent fa1fb5ed94
commit 323164f5fb
1 changed files with 2 additions and 1 deletions

View File

@ -258,8 +258,9 @@ QPixmap QCocoaTheme::fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &siz
return QPixmap();
NSRect iconRect = NSMakeRect(0, 0, size.width(), size.height());
NSGraphicsContext *gc = [NSGraphicsContext currentContext];
CGImageRef cgImage = [iconImage CGImageForProposedRect:&iconRect
context:[NSGraphicsContext currentContext]
context:([gc graphicsPort] ? gc : nil)
hints:nil];
QPixmap pixmap = QPixmap::fromImage(qt_mac_toQImage(cgImage));
return pixmap;