We use Qt Web Engine to convert an html to pdf. The code used is given below. This code works fine. The problem is that while executing the code, the console window of QTWebEngineProcess.exe appears. If the user closes the window, the pdf printing will not complete and the application hangs.
The window appears only when the code is executed from a large QT widget application(even when the code is executed just after creating QApplication Object). If we execute the same code from boost test cases, the window does not appear.
What could be the reason for showing the window and how this window showing can be avoided?
We use Qt5.12.6
QWebEnginePage report;
bool printingSuccessful = false;
bool loadSuccessful = false;
QObject::connect(&report, &QWebEnginePage::pdfPrintingFinished,
[&printingSuccessful](const QString&, const bool success)
{
printingSuccessful = success;
});
QObject::connect(&report, &QWebEnginePage::loadFinished,
[&loadSuccessful](const bool success)
{
loadSuccessful = success;
});
QEventLoop loop;
QObject::connect(&report, &QWebEnginePage::loadFinished, &loop, &QEventLoop::quit);
report.setHtml(htmlTemplate);
loop.exec();
if (!loadSuccessful)
{
throw std::exception("Could not load Html in QWebEngine.");
}
QObject::connect(&report, &QWebEnginePage::pdfPrintingFinished, &loop, &QEventLoop::quit);
report.printToPdf(QString("C:\\Projects\\xy.pdf"));
loop.exec();
if (!printingSuccessful)
{
throw std::exception("Could not print Html to PDF.");
}
