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 <morten.sorvig@digia.com>
[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];