- Qt 6.5
- Qt WebEngine
- C++ Classes
- QtWebEngineCore
- QWebEngineCookieStore
- Qt 6.5.2 Reference Documentation

# QWebEngineCookieStore Class

The QWebEngineCookieStore class provides access to Chromium's cookies. More...

Header: | #include <QWebEngineCookieStore>
CMake: | find_package(Qt6 REQUIRED COMPONENTS WebEngineCore) target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore)
qmake: | QT += webenginecore
Inherits: | QObject

- List of all members, including inherited members

## Public Types

struct | FilterRequest

## Public Functions

virtual | ~QWebEngineCookieStore()
void | deleteAllCookies()
void | deleteCookie(const QNetworkCookie &cookie, const QUrl &origin = QUrl())
void | deleteSessionCookies()
void | loadAllCookies()
void | setCookie(const QNetworkCookie &cookie, const QUrl &origin = QUrl())
void | setCookieFilter(const std::function<bool (const FilterRequest &)> &filterCallback)
void | setCookieFilter(std::function<bool (const FilterRequest &)> &&filterCallback)

## Signals

void | cookieAdded(const QNetworkCookie &cookie)
void | cookieRemoved(const QNetworkCookie &cookie)

## Detailed Description

The class allows to access HTTP cookies of Chromium for a specific profile. It can be used to synchronize cookies of Chromium and the QNetworkAccessManager, as well as to set, delete, and intercept cookies during navigation. Because cookie operations are asynchronous, the user can choose to provide a callback function to get notified about the success of the operation. The signal handlers for removal and addition should not be used to execute heavy tasks, because they might block the IO thread in case of a blocking connection.

Use QWebEngineProfile::cookieStore() and QQuickWebEngineProfile::cookieStore() to access the cookie store object for a specific profile.

## Member Function Documentation

### `[virtual]` QWebEngineCookieStore::~QWebEngineCookieStore()

Destroys this QWebEngineCookieStore object.

### `[signal]` void QWebEngineCookieStore::cookieAdded(const QNetworkCookie &cookie)

This signal is emitted whenever a new cookie is added to the cookie store.

### `[signal]` void QWebEngineCookieStore::cookieRemoved(const QNetworkCookie &cookie)

This signal is emitted whenever a cookie is deleted from the cookie store.

### void QWebEngineCookieStore::deleteAllCookies()

Deletes all the cookies in the cookie store.

Note: This operation is asynchronous.

See also loadAllCookies().

### void QWebEngineCookieStore::deleteCookie(const QNetworkCookie &cookie, const QUrl &origin = QUrl())

Deletes cookie from the cookie store. It is possible to provide an optional origin URL argument to limit the scope of the cookie to be deleted.

Note: This operation is asynchronous.

### void QWebEngineCookieStore::deleteSessionCookies()

Deletes all the session cookies in the cookie store. Session cookies do not have an expiration date assigned to them.

Note: This operation is asynchronous.

See also loadAllCookies().

### void QWebEngineCookieStore::loadAllCookies()

Loads all the cookies into the cookie store. The cookieAdded() signal is emitted on every loaded cookie. Cookies are loaded automatically when the store gets initialized, which in most cases happens on loading the first URL. However, calling this function is useful if cookies should be listed before entering the web content.

Note: This operation is asynchronous.

### void QWebEngineCookieStore::setCookie(const QNetworkCookie &cookie, const QUrl &origin = QUrl())

Adds cookie to the cookie store.

Note: If cookie specifies a QNetworkCookie::domain() that does not start with a dot, a dot is automatically prepended. To limit the cookie to the exact server, omit QNetworkCookie::domain() and set origin instead.

The provided URL should also include the scheme.

Note: This operation is asynchronous.

### void QWebEngineCookieStore::setCookieFilter(const std::function<bool (const FilterRequest &)> &filterCallback)

Installs a cookie filter that can prevent sites and resources from using cookies. The filterCallback must be a lambda or functor taking a FilterRequest structure. If the cookie access is to be accepted, the filter function should return `true`; otherwise it should return `false`.

The following code snippet illustrates how to set a cookie filter:

     profile->cookieStore()->setCookieFilter(
         [&allowThirdPartyCookies](const QWebEngineCookieStore::FilterRequest &request)
         { return !request.thirdParty || allowThirdPartyCookies; }
     );

You can unset the filter with a `nullptr` argument.

The callback should not be used to execute heavy tasks since it is running on the IO thread and therefore blocks the Chromium networking.

Note: The cookie filter also controls other features with tracking capabilities similar to those of cookies; including IndexedDB, DOM storage, filesystem API, service workers, and AppCache.

See also deleteAllCookies() and loadAllCookies().

### void QWebEngineCookieStore::setCookieFilter(std::function<bool (const FilterRequest &)> &&filterCallback)

This is an overloaded function.