Ask Your Question
4

How can you obtain the reasons for errors in QWebEnginePage::loadFinished and QWebEnginePage::pdfPrintingFinished of Qt WebEngine?

asked 2023-06-01 14:18:08 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-01 14:31:02 +0000

scrum gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-01 14:18:08 +0000

Seen: 7 times

Last updated: Jun 01 '23