QWebEngineUrlRequestInterceptor cause webview crash
-
Hi,
Today, I found my webView crashed the reason was because I delete QWebEngineUrlRequestInterceptormy interceptor is:
#include "WebViewOrderInterceptor.h" #include <QUrl> #include <QUrlQuery> #include <QDebug> WebViewOrderInterceptor::WebViewOrderInterceptor(QObject *parent) : QWebEngineUrlRequestInterceptor(parent) { } WebViewOrderInterceptor::~WebViewOrderInterceptor() { #ifdef QT_DEBUG qDebug() << __FUNCTION__; #endif } void WebViewOrderInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) { QUrl url = info.requestUrl(); if (url.path().contains("_____tmd_____/verify")) { emit verifyRequired(); } }
and the code where used interceptor is:
WebViewOrderInterceptor* interceptor = new WebViewOrderInterceptor(webview); webView->page()->profile()->setRequestInterceptor(interceptor);
after I change the parent of interceptor from webview to 'this',
the webview did not crash,
but when i want to delete interceptor by calling interceptor->deleteLater() from 'this' Object after webview was closed and destoryed,
the crash happend again.I noticed the document says
Registers a request interceptor singleton interceptor to intercept URL requests.
Does this means I just need only one interceptor for all webview.
And because of I build a interceptor for every webview, so when I delete interceptor, the webview will crash? -
Hey!
I had a very similar problem where my application crashed when I tried to delete the interceptor (see https://stackoverflow.com/questions/59631239/qwebengine-deleting-qwebengineurlrequestinterceptor-results-in-crash)I did not have multiple webviews but multiple webpages, where I always created a new interceptor. It was sufficient to only use one interceptor.
Hope this helps!