diff --git a/src/printsupport/dialogs/qprintdialog_mac.mm b/src/printsupport/dialogs/qprintdialog_mac.mm index b1b56dbf54..fa4fac1884 100644 --- a/src/printsupport/dialogs/qprintdialog_mac.mm +++ b/src/printsupport/dialogs/qprintdialog_mac.mm @@ -238,8 +238,8 @@ void QPrintDialogPrivate::openCocoaPrintPanel(Qt::WindowModality modality) int rval = [printPanel runModalWithPrintInfo:printInfo]; [delegate printPanelDidEnd:printPanel returnCode:rval contextInfo:q]; } else { - Q_ASSERT(q->parentWidget()); - QWindow *parentWindow = q->parentWidget()->windowHandle(); + Q_ASSERT(q->window()); + QWindow *parentWindow = q->window()->windowHandle(); NSWindow *window = static_cast(qApp->platformNativeInterface()->nativeResourceForWindow("nswindow", parentWindow)); [printPanel beginSheetWithPrintInfo:printInfo modalForWindow:window @@ -271,6 +271,7 @@ QPrintDialog::QPrintDialog(QWidget *parent) QPrintDialog::~QPrintDialog() { + hide(); } int QPrintDialog::exec() diff --git a/tests/auto/printsupport/dialogs/qabstractprintdialog/tst_qabstractprintdialog.cpp b/tests/auto/printsupport/dialogs/qabstractprintdialog/tst_qabstractprintdialog.cpp index 8dcfab8e64..377226d5ac 100644 --- a/tests/auto/printsupport/dialogs/qabstractprintdialog/tst_qabstractprintdialog.cpp +++ b/tests/auto/printsupport/dialogs/qabstractprintdialog/tst_qabstractprintdialog.cpp @@ -24,6 +24,8 @@ private slots: void getSetCheck(); void setMinMax(); void setFromTo(); + + void hideNativeByDestruction(); #endif }; @@ -135,6 +137,20 @@ void tst_QAbstractPrintDialog::setFromTo() QCOMPARE(obj1.maxPage(), 50); } +void tst_QAbstractPrintDialog::hideNativeByDestruction() +{ +#ifdef Q_OS_WINDOWS + QSKIP("This test fails on windows, the QPrintDialog::setVisible implementation blocks"); +#endif + + QWidget window; + QWidget *child = new QWidget(&window); + QPointer dialog = new QPrintDialog(child); + window.show(); + QVERIFY(QTest::qWaitForWindowActive(&window)); + dialog->open(); +} + #endif QTEST_MAIN(tst_QAbstractPrintDialog)