Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

[[qanda:topic_unsolved]] QWebEngineUrlRequestInterceptor cause webview crash

$
0
0

Hi,
Today, I found my webView crashed the reason was because I delete QWebEngineUrlRequestInterceptor

my 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?


Viewing all articles
Browse latest Browse all 13965

Trending Articles