QPrintDialog on macOS: Don't crash when parent is not a window
The test case is an incomplete version of the test that will be added to verify the fix for the referenced bug report. The test crashes already when showing the dialog without this fix. Task-number: QTBUG-116277 Pick-to: 6.6 6.5 6.2 Change-Id: I969a723157f6453b78bafae5cb24a6b37b1eea50 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
5fa4ce03f0
commit
e73f35d9c6
@ -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<NSWindow *>(qApp->platformNativeInterface()->nativeResourceForWindow("nswindow", parentWindow));
|
||||
[printPanel beginSheetWithPrintInfo:printInfo
|
||||
modalForWindow:window
|
||||
@ -271,6 +271,7 @@ QPrintDialog::QPrintDialog(QWidget *parent)
|
||||
|
||||
QPrintDialog::~QPrintDialog()
|
||||
{
|
||||
hide();
|
||||
}
|
||||
|
||||
int QPrintDialog::exec()
|
||||
|
@ -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<QPrintDialog> dialog = new QPrintDialog(child);
|
||||
window.show();
|
||||
QVERIFY(QTest::qWaitForWindowActive(&window));
|
||||
dialog->open();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
QTEST_MAIN(tst_QAbstractPrintDialog)
|
||||
|
Loading…
Reference in New Issue
Block a user