From 26db7de13d5885067844532b5a5814181a0ddf16 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 25 Oct 2012 15:28:07 +0200 Subject: [PATCH] Cocoa: QPrintDialog does not show/closes down immediatly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This happends if an event loop recursion ends before the native print dialog gets executed (in the same scope). The reason is that the event dispatcher gets interrupted as the first recursion ends. And (because of the big difference between how AppKit implements modal windows compared to Qt) this sets a flag in the dispatcher that gets handled on the next callback to QCocoaEventDispatcher::processPostedEvents. This will tell the dispatcher to break out of the current modal session. But since it cannot detect that an alien (native) session is now running, it closes down that session by accident instead. While code can be written in the event dispatcher to detect this problem, it ends up more clean to just work around the problem from the native dialogs instead. This to avoid making the dispatcher more complex than it already is. Native dialogs is a bit messy already, and the work-arounds needed should be isolated inside those components, and not inside the dispatcher. Change-Id: Ibfde9db4c98401562e7628da1db18d6bed619245 Reviewed-by: Morten Johan Sørvig --- src/printsupport/dialogs/qprintdialog_mac.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/printsupport/dialogs/qprintdialog_mac.mm b/src/printsupport/dialogs/qprintdialog_mac.mm index ddbe0d0f2e..dc940d5d6d 100644 --- a/src/printsupport/dialogs/qprintdialog_mac.mm +++ b/src/printsupport/dialogs/qprintdialog_mac.mm @@ -192,6 +192,11 @@ void QPrintDialogPrivate::openCocoaPrintPanel(Qt::WindowModality modality) [printPanel retain]; [printPanel setOptions:macOptions]; + // Call processEvents in case the event dispatcher has been interrupted, and needs to do + // cleanup of modal sessions. Do this before showing the native dialog, otherwise it will + // close down during the cleanup (QTBUG-17913): + qApp->processEvents(QEventLoop::ExcludeUserInputEvents, QEventLoop::ExcludeSocketNotifiers); + QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate) *delegate = [[QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate) alloc] init]; if (modality == Qt::ApplicationModal) { int rval = [printPanel runModalWithPrintInfo:printInfo];