The QWebEngineProfile class provides a web engine profile shared by multiple pages.More...
Header: | #include <QWebEngineProfile> |
qmake: | QT += webenginewidgets |
Since: | Qt 5.5 |
Inherits: | QObject |
This class was introduced in Qt 5.5.
enum | HttpCacheType { MemoryHttpCache, DiskHttpCache, NoCache } |
enum | PersistentCookiesPolicy { NoPersistentCookies, AllowPersistentCookies, ForcePersistentCookies } |
QWebEngineProfile(const QString &storageName, QObject *parent = Q_NULLPTR) | |
QWebEngineProfile(QObject *parent = Q_NULLPTR) | |
QString | cachePath() const |
void | clearAllVisitedLinks() |
void | clearVisitedLinks(const QList<QUrl> &urls) |
QWebEngineCookieStore * | cookieStore() |
QString | downloadPath() const |
QString | httpAcceptLanguage() const |
int | httpCacheMaximumSize() const |
QWebEngineProfile::HttpCacheType | httpCacheType() const |
QString | httpUserAgent() const |
bool | isOffTheRecord() const |
QWebEngineProfile::PersistentCookiesPolicy | persistentCookiesPolicy() const |
QString | persistentStoragePath() const |
QWebEngineScriptCollection * | scripts() const |
void | setCachePath(const QString &path) |
void | setDownloadPath(const QString &path) |
void | setHttpAcceptLanguage(const QString &httpAcceptLanguage) |
void | setHttpCacheMaximumSize(intmaxSize) |
void | setHttpCacheType(QWebEngineProfile::HttpCacheTypehttpCacheType) |
void | setHttpUserAgent(const QString &userAgent) |
void | setPersistentCookiesPolicy(QWebEngineProfile::PersistentCookiesPolicynewPersistentCookiesPolicy) |
void | setPersistentStoragePath(const QString &path) |
void | setUrlRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor) |
QString | storageName() const |
bool | visitedLinksContainsUrl(const QUrl &url) const |
void | downloadRequested(QWebEngineDownloadItem *download) |
A web engine profile contains settings, scripts, persistent cookie policy, and the list of visited links shared by all web engine pages that belong to the profile.
All pages that belong to the profile share a commonQWebEngineSettings instance, which can be accessed with the settings() method. Likewise, thescripts() method provides access to a commonQWebEngineScriptCollection instance.
Information about visited links is stored together with persistent cookies and other persistent data in a storage returned bystorageName(). Persistent data is stored in a subdirectory set by callingsetPersistentStoragePath(), and the cache is located in a subdirectory set by callingsetCachePath(). The cache type can be set toin-memory oron-disk by callingsetHttpCacheType(). If only the storage name is set, the subdirectories are created and named automatically. If you set any of the values manually, you should do it before creating any pages that belong to the profile.
The cache can be cleared of links by callingclearVisitedLinks() orclearAllVisitedLinks().PersistentCookiesPolicy describes whether session and persistent cookies are saved to and restored from memory or disk.
Profiles can be used to isolate pages from each other. A typical use case is a dedicatedoff-the-record profile for aprivate browsing mode. Using QWebEngineProfile() without defining a storage name constructs a new off-the-record profile that leaves no record on the local machine, and has no persistent data or cache. TheisOffTheRecord() method can be used to check whether a profile is off-the-record.
The default profile can be accessed by defaultProfile(). It is a built-in profile that all web pages not specifically created with another profile belong to.
Implementing theQWebEngineUrlRequestInterceptor interface and registering the interceptor on a profile bysetUrlRequestInterceptor() enables intercepting, blocking, and modifying URL requests (QWebEngineUrlRequestInfo) before they reach the networking stack of Chromium.
AQWebEngineUrlSchemeHandler can be registered for a profile by installUrlSchemeHandler() to add support for custom URL schemes. Requests for the scheme are then issued toQWebEngineUrlSchemeHandler::requestStarted() asQWebEngineUrlRequestJob objects.
Spellchecking HTML form fields can be enabled per profile by using the setSpellCheckEnabled() method and the current languages used for spellchecking can be set by using the setSpellCheckLanguages() method.
This enum describes the HTTP cache type:
Constant | Value | Description |
---|---|---|
QWebEngineProfile::MemoryHttpCache | 0 | Use an in-memory cache. This is the default ifoff-the-record is set. |
QWebEngineProfile::DiskHttpCache | 1 | Use a disk cache. This is the default if the profile is notoff-the-record . If set on anoff-the-record profile will instead setMemoryHttpCache . |
QWebEngineProfile::NoCache | 2 | Disable both in-memory and disk caching. (Added in Qt 5.7) |
This enum describes policy for cookie persistency:
Constant | Value | Description |
---|---|---|
QWebEngineProfile::NoPersistentCookies | 0 | Both session and persistent cookies are stored in memory. This is the only setting possible ifoff-the-record is set or no persistent data path is available. |
QWebEngineProfile::AllowPersistentCookies | 1 | Cookies marked persistent are saved to and restored from disk, whereas session cookies are only stored to disk for crash recovery. This is the default setting. |
QWebEngineProfile::ForcePersistentCookies | 2 | Both session and persistent cookies are saved to and restored from disk. |
Constructs a new profile with the storage namestorageName and parentparent.
The storage name must be unique.
A disk-based QWebEngineProfile should be destroyed on or before application exit, otherwise the cache and persistent data may not be fully flushed to disk.
See alsostorageName().
Constructs a new off-the-record profile with the parentparent.
An off-the-record profile leaves no record on the local machine, and has no persistent data or cache. Thus, the HTTP cache can only be in memory and the cookies can only be non-persistent. Trying to change these settings will have no effect.
See alsoisOffTheRecord().
[signal]
void QWebEngineProfile::downloadRequested(QWebEngineDownloadItem *download)This signal is emitted whenever a download has been triggered. Thedownload argument holds the state of the download. The download has to be explicitly accepted withQWebEngineDownloadItem::accept() or it will be cancelled by default. The download item is parented by the profile. If it is not accepted, it will be deleted immediately after the signal emission. This signal cannot be used with a queued connection.
This function was introduced in Qt 5.5.
See alsoQWebEngineDownloadItem andQWebEnginePage::download().
Returns the path used for caches.
By default, this is below StandardPaths::CacheLocation in a QtWebengine/StorageName specific subdirectory.
Note:UseQStandardPaths::writableLocation(QStandardPaths::CacheLocation) to obtain theQStandardPaths::CacheLocation path.
See alsosetCachePath(),storageName(), andQStandardPaths::writableLocation().
Clears all links from the visited links database.
See alsoclearVisitedLinks().
Clears the links inurls from the visited links database.
See alsoclearAllVisitedLinks().
Returns the cookie store for this profile.
This function was introduced in Qt 5.6.
The path to the location where the downloaded files are stored.
Note:By default, the download path isQStandardPaths::DownloadLocation.
This function was introduced in Qt 5.13.
See alsosetDownloadPath() andQStandardPaths::writableLocation().
Returns the value of the Accept-Language HTTP request-header field.
This function was introduced in Qt 5.6.
See alsosetHttpAcceptLanguage().
Returns the maximum size of the HTTP cache in bytes.
Will return0
if the size is automatically controlled byQtWebEngine.
See alsosetHttpCacheMaximumSize() andhttpCacheType().
Returns the type of HTTP cache used.
If the profile is off-the-record,MemoryHttpCache is returned.
See alsosetHttpCacheType() andcachePath().
Returns the user-agent string sent with HTTP to identify the browser.
Note:On Windows 8.1 and newer, the default user agent will always report "Windows NT 6.2" (Windows 8), unless the application does contain a manifest that declares newer Windows versions as supported.
See alsosetHttpUserAgent().
Returnstrue
if this is an off-the-record profile that leaves no record on the computer.
This will force cookies and HTTP cache to be in memory, but also force all other normally persistent data to be stored in memory.
Returns the current policy for persistent cookies.
If the profile is off-the-record,NoPersistentCookies is returned.
See alsosetPersistentCookiesPolicy().
Returns the path used to store persistent data for the browser and web content.
Persistent data includes persistent cookies, HTML5 local storage, and visited links.
By default, this is belowQStandardPaths::DataLocation in a QtWebengine/StorageName specific subdirectory.
Note:UseQStandardPaths::writableLocation(QStandardPaths::DataLocation) to obtain theQStandardPaths::DataLocation path.
See alsosetPersistentStoragePath(),storageName(), andQStandardPaths::writableLocation().
Returns the collection of scripts that are injected into all pages that share this profile.
See alsoQWebEngineScriptCollection,QWebEngineScript,QWebEnginePage::scripts(), andScript Injection.
Overrides the default path used for disk caches, setting it topath.
If set to the null string, the default path is restored.
See alsocachePath().
Overrides the default path used for download location, setting it topath.
If set to the null string, the default path is restored.
This function was introduced in Qt 5.13.
See alsodownloadPath().
Sets the value of the Accept-Language HTTP request-header field tohttpAcceptLanguage.
This function was introduced in Qt 5.6.
See alsohttpAcceptLanguage().
Sets the maximum size of the HTTP cache tomaxSize bytes.
Setting it to0
means the size will be controlled automatically byQtWebEngine.
See alsohttpCacheMaximumSize() andsetHttpCacheType().
Sets the HTTP cache type tohttpCacheType.
See alsohttpCacheType() andsetCachePath().
Overrides the default user-agent string, setting it touserAgent.
See alsohttpUserAgent().
Sets the policy for persistent cookies tonewPersistentCookiesPolicy.
See alsopersistentCookiesPolicy().
Overrides the default path used to store persistent web engine data.
Ifpath is set to the null string, the default path is restored.
See alsopersistentStoragePath().
Registers a request interceptor singletoninterceptor to intercept URL requests.
The profile does not take ownership of the pointer.
This function was introduced in Qt 5.13.
See alsoQWebEngineUrlRequestInfo andQWebEngineUrlRequestInterceptor.
Returns the storage name for the profile.
The storage name is used to give each profile that uses the disk separate subdirectories for persistent data and cache.
Returnstrue
ifurl is considered a visited link by this profile.
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.
Qt Group includes The Qt Company Oy and its global subsidiaries and affiliates.