Skip to content Skip to sidebar Skip to footer

Qt Webengine Redirect Javascript Output To Gui

I have an application that views a page in QWebEngineView widget how can I redirect my javascript console log into my GUI? it currently shows in my debug output.

Solution 1:

You have to subclass QWebEnginePage to override javaScriptConsoleMessage virtual function. (http://doc.qt.io/qt-5/qwebenginepage.html#javaScriptConsoleMessage)

class CustomPage : public QWebEnginePage
{
public:
    CustomPage(QObject* parent = 0) : QWebEnginePage(parent) {}
    virtual void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID)
    {
        // Here goes your logging code
    }
};

Post a Comment for "Qt Webengine Redirect Javascript Output To Gui"