Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.5.1
-
None
-
Windows
Description
Opening a printer using the QPrinterDialog, in Windows, it is possible for the user to select a non-existing printer (for example, a network printer that is no longer connected, or some program like "Sage PDF Converter" which is no longer installed).
QPrintDialog printDialog(m_printer, this); if (printDialog.exec() == QDialog::Accepted) { // i have tried if(!m_printer || !m_printer->isValid()) // not efective return; QPainter painter; if (! painter.begin(m_printer)) // program crashes here return; /// actual work.... painter.end(); }
If the printer does not exist, on the "painter.begin()" my code crashes, after it shows an error: "Activation Error" "Printer not activated, error code -20". After that, the code segfaults.
The stack trace (running Qt 5.5.1):
0 msgBeginFailed qprintengine_win.cpp 98 0x16c0c929
(on line if (d.lpszOutput[0]) ... which Locals and Expressions shows 0)
1 QWin32PrintEngine::begin qprintengine_win.cpp 137 0x16c0cbca
2 QPainter::begin qpainter.cpp 1808 0xc9f5f3
3 my code
I am not able to check the actual call tha may make the lpszOutput 0
(in qprintengine_win.cpp)
if (ok && StartDoc(d->hdc, &di) == SP_ERROR) { qErrnoWarning(msgBeginFailed("StartDoc", di));
It would be great if the printer.isValid() could catch this issue...
But any solution that makes the program not crash is great.