From 00cf748fa3d241e52dc0908da90864ea397dab8a Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 3 Jan 2011 15:08:22 +0100 Subject: Fix crash when closing QFontDialog::getFont() dialog Unfortunately, given the large number of ways of showing a QFontDialog, it's possible that we try to close the dialog before its event loop is finished. Setting the Cocoa font panel's isReleaseOnClose property to FALSE ensures the panel is still around when we effectively exit the dialog's event loop. Reviewed-by: Richard Task-number: QTBUG-15666 --- src/gui/dialogs/qfontdialog_mac.mm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/gui/dialogs/qfontdialog_mac.mm b/src/gui/dialogs/qfontdialog_mac.mm index 9c63dfa..e2c0ef5 100644 --- a/src/gui/dialogs/qfontdialog_mac.mm +++ b/src/gui/dialogs/qfontdialog_mac.mm @@ -116,6 +116,7 @@ const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWin - (void)showModelessPanel; - (void)showWindowModalSheet:(QWidget *)docWidget; - (void)runApplicationModalPanel; +- (BOOL)isAppModal; - (void)changeFont:(id)sender; - (void)changeAttributes:(id)sender; - (BOOL)windowShouldClose:(id)window; @@ -226,6 +227,7 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) QBoolBlocker nativeDialogOnTop(QApplicationPrivate::native_modal_dialog_active); mAppModal = true; NSWindow *ourPanel = [mStolenContentView window]; + [ourPanel setReleasedWhenClosed:NO]; [NSApp runModalForWindow:ourPanel]; QAbstractEventDispatcher::instance()->interrupt(); @@ -235,6 +237,11 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) mPriv->fontDialog()->reject(); } +- (BOOL)isAppModal +{ + return mAppModal; +} + - (void)showWindowModalSheet:(QWidget *)docWidget { #ifdef QT_MAC_USE_COCOA @@ -485,6 +492,8 @@ void QFontDialogPrivate::closeCocoaFontPanel() QT_MANGLE_NAMESPACE(QCocoaFontPanelDelegate) *theDelegate = static_cast(delegate); NSWindow *ourPanel = [theDelegate actualPanel]; [ourPanel close]; + if ([theDelegate isAppModal]) + [ourPanel release]; [theDelegate cleanUpAfterMyself]; [theDelegate release]; this->delegate = 0; -- cgit v0.12