From 0b9c7fab30bafa24ff55e7eb1bc868517d782486 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 21 Sep 2009 13:05:50 +0200 Subject: Fix QPrintDialog with no parent and no active window PrintDlgEx requires an non-null owner handle, otherwise it will fail with an "Invalid Handle" error. This caused code which popped up a print dialog as the only window in the application to fail silently and immediately return Rejected from the exec() function. To continue support for this somewhat unusual use case, we fall back to using the print dialog itself as the owner of the print dialog sheet if all else fails. Reviewed-by: Trond --- src/gui/dialogs/qprintdialog_win.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/gui/dialogs/qprintdialog_win.cpp b/src/gui/dialogs/qprintdialog_win.cpp index 1a3d2de..f66c27f 100644 --- a/src/gui/dialogs/qprintdialog_win.cpp +++ b/src/gui/dialogs/qprintdialog_win.cpp @@ -131,8 +131,8 @@ static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent, if (d->ep->printToFile) pd->Flags |= PD_PRINTTOFILE; - Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created)); - pd->hwndOwner = parent ? parent->winId() : 0; + Q_ASSERT(parent != 0 && parent->testAttribute(Qt::WA_WState_Created)); + pd->hwndOwner = parent->winId(); pd->lpPageRanges[0].nFromPage = qMax(pdlg->fromPage(), pdlg->minPage()); pd->lpPageRanges[0].nToPage = (pdlg->toPage() > 0) ? qMin(pdlg->toPage(), pdlg->maxPage()) : 1; pd->nCopies = d->ep->num_copies; @@ -212,6 +212,10 @@ int QPrintDialogPrivate::openWindowsPrintDialogModally() else parent = QApplication::activeWindow(); + // If there is no window, fall back to the print dialog itself + if (parent == 0) + parent = q; + QWidget modal_widget; modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true); modal_widget.setParent(parent, Qt::Window); -- cgit v0.12