Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are several ways to obtain the reasons for errors in QWebEnginePage::loadFinished and QWebEnginePage::pdfPrintingFinished of Qt WebEngine:

  1. Check the error code and description

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();
    }
}
  1. Enable verbose logging

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");
  1. Use a debugging tool

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.