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.
Asked
Active
Viewed 2,302 times
2

Farahats9
- 535
- 1
- 9
- 22
-
If you want to redirect all debug output, see: https://stackoverflow.com/questions/4954140/how-to-redirect-qdebug-qwarning-qcritical-etc-output – MrEricSir Oct 13 '17 at 21:24
-
I tried that but it seems to see only `QtDebugMsg` from my code and not the javascript console messages – Farahats9 Oct 14 '17 at 15:10
1 Answers
6
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
}
};

Sz. David
- 111
- 1
- 6
-
1If anyone is wondering how to attach this to a `QWebEngineView`, you need to do `QWebEngineView view; CustomPage page; view.setPage(&page);`. – Donald Duck Sep 25 '20 at 12:10
-
1It is *so* annoying that they didn't just put a signal for that in the default `QWebEnginePage` implementation... – Jason C Feb 23 '22 at 01:43