K
K
Kostyan Kondr2016-05-04 14:47:44
Webkit
Kostyan Kondr, 2016-05-04 14:47:44

How to make qt webkit save javascript logging level?

I ran into the following problem and I can’t figure it out: qtwebkit, when working with js on pages, displays console.warn and console.error at the debug level, and not at the corresponding warning and critical (or fatal, I’m not sure here). Tell me what can I do about it? How to combine js and qt logging?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EXL, 2016-05-05
@kondr1

Starting with Qt 5.6 and WebEngine, logging levels are available in the javaScriptConsoleMessage() function:
doc.qt.io/qt-5/qwebenginepage.html#javaScriptConso...
doc.qt.io/qt-5/qwebenginepage.html#JavaScriptConso.. Inherit from QWebEnginePage
, overload javaScriptConsoleMessage() and use as you need, as an example:

void WebEnginePage::javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level,
                                       const QString &message,
                                       int lineNumber,
                                       const QString &sourceID)
{
    Q_UNUSED(lineNumber);
    Q_UNUSED(sourceID);

    switch (level) {
    default:
    case QWebEnginePage::InfoMessageLevel:
        qDebug() << message;
        break;
    case QWebEnginePage::WarningMessageLevel:
        qWarning() << message;
        break;
    case QWebEnginePage::ErrorMessageLevel:
        qCritical() << message;
        break;
    }
}

PS I have Qt 5.5.1, there is no way to check, but the documentation says, they say: Since Qt 5.6, the default implementation logs the messages in a js logging category . So maybe you don't even need to reload anything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question