I'm trying to create a Dialog in Qt which loads a URL (which I do not want to expose to the end-user, hence a Dialog). Once the user has entered their credentials on the page, the server returns a redirect URL which I want to capture. How can I do this?
QtWebkit made this easy to do as QWebView had a QNetworkAccessManager object. But with QtWebEngine, the QWebEngineView class does not have this capability. The former also allowed HTTP headers to be set for any requests by using the QNetworkRequest class and then load requests with these specific requests in QWebView. How do I do this with QWebEngineView?
Since Qt 5.6 the proposed solution for what you are trying to achieve with
QWebEngineView
is QWebEngineUrlRequestInterceptor:It is an abstract class which means you need to subclass it to get what you want:
Then you need to register the pointer to this interceptor in
QWebEngineProfile
for a particularQWebEnginePage
, like this: