Clear cookies in QtWebEngine
Asked Answered
U

2

5

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.

Unlock answered 10/1, 2016 at 13:18 Comment(0)
B
8

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);
Boland answered 10/1, 2016 at 14:43 Comment(1)
It's the default setting in Qt6Vancouver
H
12

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();
Hyperbola answered 30/7, 2016 at 18:13 Comment(0)
B
8

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);
Boland answered 10/1, 2016 at 14:43 Comment(1)
It's the default setting in Qt6Vancouver

© 2022 - 2024 — McMap. All rights reserved.