I need to intercept requests made in our WebEngine qml component in our Qt application.
I have found documentation on QWebEngineUrlRequestInterceptor which seems to do just this here http://doc.qt.io/qt-5/qwebengineprofile.html#details and here http://doc.qt.io/qt-5/qwebengineurlrequestinterceptor.html#details. However I haven't found any code examples on how to do this in Qt/C++.
Any help is appreciated.
Managed to puzzle it together with the help of this post: https://forum.qt.io/topic/69135/how-to-send-network-requests-in-qwebengine/2
This is my solution to hook up a QWebEngineUrlRequestInterceptor:
.h file
.cpp file
main.cpp file
The QWebEngineUrlRequestInterceptor class provides an abstract base class for URL interception, i recommend it to handle custom protocols, (mail://, example:// ....)
Let's implement it by subclasing QWebEngineUrlRequestInterceptor:
Your header file exampleurlschemehandler.h file:
Your cpp file:
Now install it in your default QWebEngineProfile:
Other method, to handle HTTP/HTTPS request is subclassing QWebEnginePage, and reimplementing acceptNavigationRequest():
Now, set this page in your QWebEngineView.