summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoamenuitem.mm
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2014-11-17 18:35:52 +0100
committerDavid Faure <david.faure@kdab.com>2014-11-21 00:42:55 +0100
commiteb466b636b97251d273aedddfe66b15fe994d375 (patch)
treedbc223dcb06a4908d5a75e3b599c5cfe6ae59507 /src/plugins/platforms/cocoa/qcocoamenuitem.mm
parent6c5d1dbd75f4edf886420cb07efeb1c20a1b0bbf (diff)
Fix QAction::setFont crash on OSX, when font is unknown.
customMenuFont was null, so objects was an empty array, and NSDictionary throws an exception when being called with arrays of different sizes. Task-number: QTBUG-42728 Change-Id: I8cdab449fd8c1d12b65c46dd5617a7f5e3e96c6e Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoamenuitem.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoamenuitem.mm19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm
index 791b0805d0..251fe9485c 100644
--- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm
+++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm
@@ -323,17 +323,22 @@ NSMenuItem *QCocoaMenuItem::sync()
text += QLatin1String(" (") + accel.toString(QKeySequence::NativeText) + QLatin1String(")");
QString finalString = qt_mac_removeMnemonics(text);
+ bool useAttributedTitle = false;
// Cocoa Font and title
if (m_font.resolve()) {
NSFont *customMenuFont = [NSFont fontWithName:QCFString::toNSString(m_font.family())
size:m_font.pointSize()];
- NSArray *keys = [NSArray arrayWithObjects:NSFontAttributeName, nil];
- NSArray *objects = [NSArray arrayWithObjects:customMenuFont, nil];
- NSDictionary *attributes = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
- NSAttributedString *str = [[[NSAttributedString alloc] initWithString:QCFString::toNSString(finalString)
- attributes:attributes] autorelease];
- [m_native setAttributedTitle: str];
- } else {
+ if (customMenuFont) {
+ NSArray *keys = [NSArray arrayWithObjects:NSFontAttributeName, nil];
+ NSArray *objects = [NSArray arrayWithObjects:customMenuFont, nil];
+ NSDictionary *attributes = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
+ NSAttributedString *str = [[[NSAttributedString alloc] initWithString:QCFString::toNSString(finalString)
+ attributes:attributes] autorelease];
+ [m_native setAttributedTitle: str];
+ useAttributedTitle = true;
+ }
+ }
+ if (!useAttributedTitle) {
[m_native setTitle: QCFString::toNSString(finalString)];
}