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 <Friedemann.Kleint@qt.io>
This commit is contained in:
Daniel Teske 2017-06-15 15:05:04 +02:00
parent 06b5e4d706
commit e7471da4d6

View File

@ -449,7 +449,9 @@ QStringList QWindowsPrintDevice::availablePrintDeviceIds()
QString QWindowsPrintDevice::defaultPrintDeviceId() QString QWindowsPrintDevice::defaultPrintDeviceId()
{ {
DWORD size = 0; DWORD size = 0;
GetDefaultPrinter(NULL, &size); if (GetDefaultPrinter(NULL, &size) == ERROR_FILE_NOT_FOUND)
return QString();
QScopedArrayPointer<wchar_t> name(new wchar_t[size]); QScopedArrayPointer<wchar_t> name(new wchar_t[size]);
GetDefaultPrinter(name.data(), &size); GetDefaultPrinter(name.data(), &size);
return QString::fromWCharArray(name.data()); return QString::fromWCharArray(name.data());