From e7471da4d6e025efc6fe2a8e9c1890e593b2d6b2 Mon Sep 17 00:00:00 2001 From: Daniel Teske Date: Thu, 15 Jun 2017 15:05:04 +0200 Subject: [PATCH] Windows Printer: Handle no default printer case GetDefaultPrinter can return ERROR_FILE_NOT_FOUND. In that case just return a empty string. Task-number: QTBUG-53290 Change-Id: Ib0e28b3425d100bc185d1d8827dc6b7fd90cbbeb Reviewed-by: Friedemann Kleint --- src/plugins/printsupport/windows/qwindowsprintdevice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/printsupport/windows/qwindowsprintdevice.cpp b/src/plugins/printsupport/windows/qwindowsprintdevice.cpp index 99e8ec8999..1cb14514ee 100644 --- a/src/plugins/printsupport/windows/qwindowsprintdevice.cpp +++ b/src/plugins/printsupport/windows/qwindowsprintdevice.cpp @@ -449,7 +449,9 @@ QStringList QWindowsPrintDevice::availablePrintDeviceIds() QString QWindowsPrintDevice::defaultPrintDeviceId() { DWORD size = 0; - GetDefaultPrinter(NULL, &size); + if (GetDefaultPrinter(NULL, &size) == ERROR_FILE_NOT_FOUND) + return QString(); + QScopedArrayPointer name(new wchar_t[size]); GetDefaultPrinter(name.data(), &size); return QString::fromWCharArray(name.data());