diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index e0eec585fa..39d7e48389 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -1174,6 +1174,16 @@ void QWin32PrintEnginePrivate::doReinit() if (state == QPrinter::Active) { reinit = true; } else { + if (!name.isEmpty()) { + HANDLE hCheckPrinter; + if (!OpenPrinter((LPWSTR)name.utf16(), (LPHANDLE)&hCheckPrinter, 0)) { + initialize(); + return; + } else { + ClosePrinter(hCheckPrinter); + hCheckPrinter = 0; + } + } resetDC(); initDevRects(); reinit = false; @@ -1296,9 +1306,12 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant & case PPK_PrinterName: d->name = value.toString(); - if(d->name.isEmpty()) + if (d->name.isEmpty()) { d->queryDefault(); - d->initialize(); + d->initialize(); + } else { + d->doReinit(); + } break; case PPK_Resolution: diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp index 9e08c594c4..4b4756bd5e 100644 --- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp +++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp @@ -985,7 +985,9 @@ void tst_QPrinter::taskQTBUG4497_reusePrinterOnDifferentFiles() QFile file2("out2.ps"); QVERIFY(file2.open(QIODevice::ReadOnly)); +#ifndef Q_OS_WIN QEXPECT_FAIL("", "QTBUG-22562, QTBUG-22296", Abort); +#endif QCOMPARE(file1.readAll(), file2.readAll()); }