5
votes

I'm upgrading an application from QtWebKit to QtWebEngine. The application relied on that WebKit didn't keep cookies after closing the app but WebEngine seems to keep them by default.

I'm not familiar with Qt at all. I've been browsing the documentation but I can't seem to find the right API calls to delete them. The application just has a simple QWebEngineView for the front end.

2
Using Qt 5.6 (windows) if that matters. - toster-cx

2 Answers

12
votes

In case when there is no need to change PersistentCookiesPolicy, but you only need to clean Cookies, then you may use method deleteAllCookies() of the class QWebEngineCookieStore.

So you can do something like this:

webEngineView->page()->profile()->cookieStore()->deleteAllCookies();
8
votes

There is QWebEngineProfile class that you may use.

void QWebEngineProfile::setPersistentCookiesPolicy(QWebEngineProfile::PersistentCookiesPolicy newPersistentCookiesPolicy)

Sets the policy for persistent cookies to newPersistentCookiesPolicy.

So you can do something like this:

webEngineView->page()->profile()->setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);