There are several ways to obtain the reasons for errors in QWebEnginePage::loadFinished and QWebEnginePage::pdfPrintingFinished of Qt WebEngine:
In the QWebEnginePage::loadFinished and QWebEnginePage::pdfPrintingFinished signals, you can check the error code and description by calling the error() function of the QWebEnginePage object.
Example:
QWebEnginePage* page = /* ... */;
connect(page, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
void MyClass::onLoadFinished(bool ok)
{
if (!ok) {
QWebEngineError error = page->error();
qDebug() << "Load error:" << error.code() << error.description();
}
}
You can enable verbose logging for Qt WebEngine by setting the environment variable QTWEBENGINECHROMIUMSWITCHES to "--enable-logging=stderr". This will cause the Qt WebEngine process to output detailed log messages to stderr.
Example:
qputenv("QTWEBENGINE_CHROMIUM_SWITCHES", "--enable-logging=stderr");
You can use a debugging tool such as Chrome DevTools to inspect the network requests and responses, as well as any errors that occur during the loading process.
To enable remote debugging for Qt WebEngine, you can pass the "--remote-debugging-port" and "--no-sandbox" command-line options when launching your application.
Example:
QApplication app(argc, argv);
QWebEngineView view;
view.page()->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
view.page()->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
view.page()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
view.page()->load(QUrl("https://www.google.com"));
view.show();
qputenv("QTWEBENGINE_CHROMIUM_SWITCHES", "--remote-debugging-port=9222 --no-sandbox");
app.exec();
Then, you can open Chrome and navigate to "http://localhost:9222" to connect to the Qt WebEngine debugger.
Asked: 2023-06-01 14:18:08 +0000
Seen: 7 times
Last updated: Jun 01 '23