QWebEngineProfile 类提供由多个页面共享的 Web 引擎 Profile (配置文件)。 更多...
头: | #include <QWebEngineProfile> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS WebEngineCore)
target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore) |
qmake: | QT += webenginecore |
继承: | QObject |
enum | HttpCacheType { MemoryHttpCache, DiskHttpCache, NoCache } |
enum | PersistentCookiesPolicy { NoPersistentCookies, AllowPersistentCookies, ForcePersistentCookies } |
QWebEngineProfile (QObject * parent = nullptr) | |
QWebEngineProfile (const QString & storageName , QObject * parent = nullptr) | |
QString | cachePath () const |
void | clearAllVisitedLinks () |
void | clearHttpCache () |
void | clearVisitedLinks (const QList<QUrl> & urls ) |
QWebEngineClientCertificateStore * | clientCertificateStore () |
QWebEngineCookieStore * | cookieStore () |
QString | downloadPath () const |
QString | httpAcceptLanguage () const |
int | httpCacheMaximumSize () const |
QWebEngineProfile::HttpCacheType | httpCacheType () const |
QString | httpUserAgent () const |
void | installUrlSchemeHandler (const QByteArray & scheme , QWebEngineUrlSchemeHandler * handler ) |
bool | isOffTheRecord () const |
bool | isPushServiceEnabled () const |
bool | isSpellCheckEnabled () const |
QWebEngineProfile::PersistentCookiesPolicy | persistentCookiesPolicy () const |
QString | persistentStoragePath () const |
void | removeAllUrlSchemeHandlers () |
void | removeUrlScheme (const QByteArray & scheme ) |
void | removeUrlSchemeHandler (QWebEngineUrlSchemeHandler * handler ) |
void | requestIconForIconURL (const QUrl & url , int desiredSizeInPixel , std::function<void (const QIcon &, const QUrl &)> iconAvailableCallback ) const |
void | requestIconForPageURL (const QUrl & url , int desiredSizeInPixel , std::function<void (const QIcon &, const QUrl &, const QUrl &)> iconAvailableCallback ) const |
QWebEngineScriptCollection * | scripts () const |
void | setCachePath (const QString & path ) |
void | setDownloadPath (const QString & path ) |
void | setHttpAcceptLanguage (const QString & httpAcceptLanguage ) |
void | setHttpCacheMaximumSize (int maxSize ) |
void | setHttpCacheType (QWebEngineProfile::HttpCacheType httpCacheType ) |
void | setHttpUserAgent (const QString & userAgent ) |
void | setNotificationPresenter (std::function<void (std::unique_ptr<QWebEngineNotification>)> notificationPresenter ) |
void | setPersistentCookiesPolicy (QWebEngineProfile::PersistentCookiesPolicy newPersistentCookiesPolicy ) |
void | setPersistentStoragePath (const QString & path ) |
void | setPushServiceEnabled (bool enable ) |
void | setSpellCheckEnabled (bool enable ) |
void | setSpellCheckLanguages (const QStringList & languages ) |
void | setUrlRequestInterceptor (QWebEngineUrlRequestInterceptor * interceptor ) |
QWebEngineSettings * | settings () const |
QStringList | spellCheckLanguages () const |
QString | storageName () const |
const QWebEngineUrlSchemeHandler * | urlSchemeHandler (const QByteArray & scheme ) const |
bool | visitedLinksContainsUrl (const QUrl & url ) const |
void | downloadRequested (QWebEngineDownloadRequest * download ) |
QWebEngineProfile * | defaultProfile () |
Web 引擎 Profile (配置文件) 包含设置、脚本、持久性 Cookie 策略及属于 Profile 由所有 Web 引擎页面共享的拜访链接列表。
属于 Profile (配置文件) 的所有页面共享公共 QWebEngineSettings 实例,可以访问采用 settings () 方法。同样, scripts () 方法提供访问为公共 QWebEngineScriptCollection 实例。
Information about visited links is stored together with persistent cookies and other persistent data in a storage returned by storageName (). Persistent data is stored in a subdirectory set by calling setPersistentStoragePath (), and the cache is located in a subdirectory set by calling setCachePath (). The cache type can be set to in-memory or on-disk 通过调用 setHttpCacheType (). 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.
可以清零缓存链接通过调用 clearVisitedLinks () 或 clearAllVisitedLinks (). PersistentCookiesPolicy 描述是否把会话和持久 Cookie 保存到内存或磁盘并从中还原。
Profiles can be used to isolate pages from each other. A typical use case is a dedicated off-the-record profile 对于 隐私浏览 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. The isOffTheRecord () 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.
实现 QWebEngineUrlRequestInterceptor interface and registering the interceptor on a profile by setUrlRequestInterceptor () enables intercepting, blocking, and modifying URL requests ( QWebEngineUrlRequestInfo ) 在它们到达 Chromium 网络堆栈之前。
A QWebEngineUrlSchemeHandler 可以注册为 Profile (配置文件) 通过 installUrlSchemeHandler () 去添加对自定义 URL 方案的支持。然后把方案请求发送给 QWebEngineUrlSchemeHandler::requestStarted () 作为 QWebEngineUrlRequestJob 对象。
可以启用每个 Profile (配置文件) 的拼写检查 HTML 表单字段通过使用 setSpellCheckEnabled () 方法和可以设置用于拼写检查的当前语言通过使用 setSpellCheckLanguages () 方法。
此枚举描述 HTTP 缓存类型:
常量 | 值 | 描述 |
---|---|---|
QWebEngineProfile::MemoryHttpCache
|
0
|
使用内存中的缓存。这是默认设置若
off-the-record
有设置。
|
QWebEngineProfile::DiskHttpCache
|
1
|
使用磁盘缓存。这是默认的若 Profile (配置文件) 不为
off-the-record
。若设置在
off-the-record
Profile (配置文件) 将代替设置
MemoryHttpCache
.
|
QWebEngineProfile::NoCache
|
2
|
禁用内存和磁盘缓存。(在 Qt 5.7 添加) |
此枚举描述 Cookie 持久性策略:
常量 | 值 | 描述 |
---|---|---|
QWebEngineProfile::NoPersistentCookies
|
0
|
Both session and persistent cookies are stored in memory. This is the only setting possible if
off-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
|
会话和持久 Cookie 均保存到磁盘并从中还原。 |
[explicit]
QWebEngineProfile::
QWebEngineProfile
(
QObject
*
parent
= nullptr)
构造新 off-the-record Profile 采用父级 parent .
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.
另请参阅 isOffTheRecord ().
[explicit]
QWebEngineProfile::
QWebEngineProfile
(const
QString
&
storageName
,
QObject
*
parent
= nullptr)
构造新 Profile (配置文件) 采用存储名称 storageName 和父级 parent .
存储名称必须唯一。
基于磁盘的 QWebEngineProfile 应该在应用程序退出时 (或之前) 被销毁,否则可能不会把缓存和持久数据完全刷新到磁盘。
另请参阅 storageName ().
返回用于缓存的路径。
默认情况下,这位于 QtWebengine/StorageName 特定子目录中 StandardPaths::CacheLocation 下。
注意: 使用 QStandardPaths::writableLocation ( QStandardPaths::CacheLocation ) 以获得 QStandardPaths::CacheLocation 路径。
另请参阅 setCachePath (), storageName (),和 QStandardPaths::writableLocation ().
清零所有链接从拜访链接数据库。
另请参阅 clearVisitedLinks ().
移除 Profile 的缓存条目。
清零链接在 urls 从拜访链接数据库
另请参阅 clearAllVisitedLinks ().
返回 Profile (配置文件) 的客户端证书存储。
返回用于此 Profile (配置文件) 的 Cookie 存储。
[static]
QWebEngineProfile
*QWebEngineProfile::
defaultProfile
()
返回默认 Profile (配置文件)。
The default profile is off-the-record.
另请参阅 storageName ().
下载文件存储位置的路径。
注意: 默认情况下,下载路径为 QStandardPaths::DownloadLocation .
另请参阅 setDownloadPath () 和 QStandardPaths::writableLocation ().
[signal]
void
QWebEngineProfile::
downloadRequested
(
QWebEngineDownloadRequest
*
download
)
此信号被发射每当下载已被触发。 download 自变量保持下载的状态。下载必须被明确接受采用 QWebEngineDownloadRequest::accept (),否则默认情况下,它会被取消。下载项的父级是 Profile。若不接受,在信号发出后它会被立即删除。此信号不可以用于队列连接。
另请参阅 QWebEngineDownloadRequest and QWebEnginePage::download ().
返回 Accept-Language HTTP 请求头字段的值。
另请参阅 setHttpAcceptLanguage ().
返回 HTTP 缓存的最大尺寸,以字节为单位。
将返回
0
若尺寸被自动控制由
QtWebEngine
.
另请参阅 setHttpCacheMaximumSize () 和 httpCacheType ().
返回所用 HTTP 缓存类型。
若 Profile (配置文件) 为 off-the-record, MemoryHttpCache 被返回。
另请参阅 setHttpCacheType () 和 cachePath ().
返回与 HTTP 一起发送,以标识浏览器的用户代理字符串。
注意: 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.
另请参阅 setHttpUserAgent ().
注册处理程序 handler 为自定义 URL 方案 scheme 在 Profile (配置文件) 中。
它是必要的,首先注册方案采用 QWebEngineUrlScheme::registerScheme 在应用程序启动时。
返回
true
若这是 off-the-record Profile 配置文件 (离开计算机无记录)。
这将强制 Cookie 和 HTTP 缓存在内存中,但也强制所有其它通常持久数据存储在内存中。
[since 6.5]
bool
QWebEngineProfile::
isPushServiceEnabled
() const
返回
true
if the push messaging service is enabled.
注意: By default the push messaging service is disabled.
该函数在 Qt 6.5 引入。
另请参阅 setPushServiceEnabled ().
返回
true
若拼写检查器被启用;否则返回
false
.
另请参阅 setSpellCheckEnabled ().
返回持久 Cookie 的当前策略。
若 Profile (配置文件) 为 off-the-record, NoPersistentCookies 被返回。
另请参阅 setPersistentCookiesPolicy ().
返回用于存储浏览器和 Web 内容持久数据的路径。
持久数据包括:持久 Cookie、HTML5 本地存储、拜访链接。
By default, this is below QStandardPaths::DataLocation in a QtWebengine/StorageName specific subdirectory.
注意: 使用 QStandardPaths::writableLocation (QStandardPaths::DataLocation) to obtain the QStandardPaths::DataLocation path.
另请参阅 setPersistentStoragePath (), storageName (),和 QStandardPaths::writableLocation ().
移除 Profile (配置文件) 中安装的所有自定义 URL 方案处理程序。
称除自定义 URL 方案 scheme 从 Profile (配置文件)。
另请参阅 removeUrlSchemeHandler ().
移除自定义 URL 方案处理程序 handler 从 Profile (配置文件)。
另请参阅 removeUrlScheme ().
[since 6.2]
void
QWebEngineProfile::
requestIconForIconURL
(const
QUrl
&
url
,
int
desiredSizeInPixel
,
std::function
<
void
(const
QIcon
&, const
QUrl
&)>
iconAvailableCallback
) const
Requests an icon with the specified url from the database. Each profile has its own icon database and it is stored in the persistent storage thus the stored icons can be accessed without network connection too. The icon must be previously loaded to be stored in the database.
url specifies the URL of the icon. In case of more than one available icons the one with the size closest to desiredSizeInPixel will be returned. The result icon is resized to desiredSizeInPixel . If desiredSizeInPixel is 0 the largest available icon is returned.
This function is asynchronous and the result is returned by iconAvailableCallback . The callback is called if a request for an icon is performed. If the requested icon is available, the first parameter (with type QIcon ) is the result. Otherwise, it is null.
The second parameter stores the URL of the requested icon. It is empty if the icon can't be fetched.
注意: Icons can't be requested with an off-the-record profile.
该函数在 Qt 6.2 引入。
另请参阅 requestIconForPageURL ().
[since 6.2]
void
QWebEngineProfile::
requestIconForPageURL
(const
QUrl
&
url
,
int
desiredSizeInPixel
,
std::function
<
void
(const
QIcon
&, const
QUrl
&, const
QUrl
&)>
iconAvailableCallback
) const
Requests an icon for a previously loaded page with this profile from the database. Each profile has its own icon database and it is stored in the persistent storage thus the stored icons can be accessed without network connection too. The icon must be previously loaded to be stored in the database.
url specifies the URL of the page what the icon is requested for. In case of more than one available icons the one with the size closest to desiredSizeInPixel will be returned. The result icon is resized to desiredSizeInPixel . If desiredSizeInPixel is 0 the largest available icon is returned.
This function is asynchronous and the result is returned by iconAvailableCallback . The callback is called if a request for an icon is performed. If the requested icon is available, the first parameter (with type QIcon ) is the result. Otherwise, it is null.
The second parameter stores the URL of the requested icon. It is empty if the icon can't be fetched.
The third parameter stores the URL of the page which the icon is assigned.
注意: Icons can't be requested with an off-the-record profile.
该函数在 Qt 6.2 引入。
另请参阅 requestIconForIconURL ().
返回注入到共享此 Profile (配置文件) 的所有页面中的脚本集合。
另请参阅 QWebEngineScriptCollection , QWebEngineScript , QWebEnginePage::scripts (),和 脚本注入 .
覆盖用于磁盘缓存的默认路径,将其设为 path .
若设为 null 字符串,则还原默认路径。
另请参阅 cachePath ().
覆盖用于下载位置的默认路径,将其设为 path .
若设为 null 字符串,则还原默认路径。
另请参阅 downloadPath ().
把 Accept-Language HTTP 请求头字段值设为 httpAcceptLanguage .
另请参阅 httpAcceptLanguage ().
把 HTTP 缓存的最大尺寸设为 maxSize 字节。
把它设为
0
意味着尺寸将被自动控制由
QtWebEngine
.
另请参阅 httpCacheMaximumSize () 和 setHttpCacheType ().
把 HTTP 缓存类型设为 httpCacheType .
另请参阅 httpCacheType () 和 setCachePath ().
覆写默认用户代理字符串,将其设为 userAgent .
另请参阅 httpUserAgent ().
设置函数 notificationPresenter 负责呈现已发送通知。
另请参阅 QWebEngineNotification .
把持久 Cookie 策略设为 newPersistentCookiesPolicy .
另请参阅 persistentCookiesPolicy ().
覆盖用于存储持久 Web 引擎数据的默认路径。
若 path 设为 null 字符串,则还原默认路径。
另请参阅 persistentStoragePath ().
[since 6.5]
void
QWebEngineProfile::
setPushServiceEnabled
(
bool
enable
)
Enables the push messaging service if
enable
is
true
,否则禁用它。
注意: Qt WebEngine uses Firebase Cloud Messaging (FCM) as a browser push service. Therefore, all push messages will go through the Google push service and its respective servers.
该函数在 Qt 6.5 引入。
另请参阅 isPushServiceEnabled ().
启用拼写检查器,若
enable
is
true
,否则禁用它。
另请参阅 isSpellCheckEnabled ().
设置当前列表
languages
为拼写检查器。每种语言应该匹配的名称源于
.bdic
字典。例如,语言
en-US
将加载
en-US.bdic
字典文件。
见 拼写检查器特征文档编制 如何搜索字典文件。
了解更多信息关于如何编译
.bdic
字典,见
拼写检查器范例
.
另请参阅 spellCheckLanguages ().
注册请求拦截器单例 interceptor 到拦截 URL 请求。
Profile (配置文件) 不拥有指针的所有权。
另请参阅 QWebEngineUrlRequestInfo and QWebEngineUrlRequestInterceptor .
返回此 Profile (配置文件) 中所有页面的默认设置。
返回拼写检查器所用的语言列表。
另请参阅 setSpellCheckLanguages ().
返回 Profile (配置文件) 的存储名称。
存储名称为每个 Profile 配置文件 (对于持久数据和缓存) 提供使用磁盘的单独子目录。
返回自定义 URL 方案的处理程序寄存器,对于 URL 方案 scheme .
返回
true
if
url
被认为通过此 Profile (配置文件) 拜访过链接。