@SGaist said in Application crahes on QWebEnginePage printing attempt:
checking that the call to page returns a valid pointer.
Thank you.
With the clue I had from this response, and with the help of demobrowser example which is bundled with Qt-5.6 I rewrote the code and could send the page to printer successfully.
the code after the modification:
QWebEngineView *view = new QWebEngineView(this); view->setHtml("<h1>Hello</h1>", QUrl("about:blank")); printRequest(view->page());the functions are defined as following
void MainWindow::slotHandlePagePrinted(bool result) { Q_UNUSED(result); delete printer; printer = nullptr; } void MainWindow::printRequest(QWebEnginePage *page) { if (printer) return; printer = new QPrinter(); QScopedPointer<QPrintDialog> dialog(new QPrintDialog(printer, this)); if (dialog->exec() != QDialog::Accepted) { slotHandlePagePrinted(true); return; } else { page->print(printer, [=](bool) {}); } }and in the header file:
private slots: void slotHandlePagePrinted(bool result); private: QPrinter *printer; void printRequest(QWebEnginePage *page);