Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear cookies in QtWebEngine

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.

like image 807
toster-cx Avatar asked Jan 10 '16 13:01

toster-cx


2 Answers

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();
like image 111
Denys Rogovchenko Avatar answered Sep 18 '22 21:09

Denys Rogovchenko


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);
like image 32
Evgeny Avatar answered Sep 17 '22 21:09

Evgeny