QWebEngineProfile 类

QWebEngineProfile class provides a web engine profile shared by multiple pages. 更多...

头: #include <QWebEngineProfile>
qmake: QT += webenginewidgets
Since: Qt 5.5
继承: QObject

公共类型

enum HttpCacheType { MemoryHttpCache, DiskHttpCache, NoCache }
enum PersistentCookiesPolicy { NoPersistentCookies, AllowPersistentCookies, ForcePersistentCookies }

公共函数

QWebEngineProfile (QObject * parent = Q_NULLPTR)
QWebEngineProfile (const QString & storageName , QObject * parent = Q_NULLPTR)
QString cachePath () const
void clearAllVisitedLinks ()
void clearHttpCache ()
void clearVisitedLinks (const QList<QUrl> & urls )
QWebEngineCookieStore * cookieStore ()
QString httpAcceptLanguage () const
int httpCacheMaximumSize () const
HttpCacheType httpCacheType () const
QString httpUserAgent () const
void installUrlSchemeHandler (const QByteArray & scheme , QWebEngineUrlSchemeHandler * handler )
bool isOffTheRecord () const
bool isSpellCheckEnabled () const
PersistentCookiesPolicy persistentCookiesPolicy () const
QString persistentStoragePath () const
void removeAllUrlSchemeHandlers ()
void removeUrlScheme (const QByteArray & scheme )
void removeUrlSchemeHandler (QWebEngineUrlSchemeHandler * handler )
QWebEngineScriptCollection * scripts () const
void setCachePath (const QString & path )
void setHttpAcceptLanguage (const QString & httpAcceptLanguage )
void setHttpCacheMaximumSize (int maxSize )
void setHttpCacheType (QWebEngineProfile::HttpCacheType httpCacheType )
void setHttpUserAgent (const QString & userAgent )
void setPersistentCookiesPolicy (QWebEngineProfile::PersistentCookiesPolicy newPersistentCookiesPolicy )
void setPersistentStoragePath (const QString & path )
void setRequestInterceptor (QWebEngineUrlRequestInterceptor * interceptor )
void setSpellCheckEnabled (bool enable )
void setSpellCheckLanguages (const QStringList & languages )
QWebEngineSettings * settings () const
QStringList spellCheckLanguages () const
QString storageName () const
const QWebEngineUrlSchemeHandler * urlSchemeHandler (const QByteArray & scheme ) const
bool visitedLinksContainsUrl (const QUrl & url ) const

信号

void downloadRequested (QWebEngineDownloadItem * download )

静态公共成员

QWebEngineProfile * defaultProfile ()

额外继承成员

详细描述

QWebEngineProfile class provides a web engine profile shared by multiple pages.

Web 引擎配置文件包含设置、脚本、持久性 Cookie 策略及属于配置文件由所有 Web 引擎页面共享的拜访链接列表。

属于配置文件的所有页面共享公共 QWebEngineSettings 实例,可以访问采用 settings () 方法。同样, scripts () 方法提供访问为公共 QWebEngineScriptCollection 实例。

Information about visited links is stored together with persistent cookies and other persistent data in a storage returned by persistentStoragePath (). The cache can be cleared of links by 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 setRequestInterceptor () enables intercepting, blocking, and modifying URL requests ( QWebEngineUrlRequestInfo ) 在它们到达 Chromium 网络堆栈之前。

QWebEngineUrlSchemeHandler 可以被注册为配置文件通过 installUrlSchemeHandler () 去添加对自定义 URL 方案的支持。然后把方案请求发送给 QWebEngineUrlSchemeHandler::requestStarted () 作为 QWebEngineUrlRequestJob 对象。

可以启用每个配置文件的拼写检查 HTML 表单字段通过使用 setSpellCheckEnabled () 方法和可以设置用于拼写检查的当前语言通过使用 setSpellCheckLanguages () 方法。

成员类型文档编制

enum QWebEngineProfile:: HttpCacheType

此枚举描述 HTTP 缓存类型:

常量 描述
QWebEngineProfile::MemoryHttpCache 0 Use an in-memory cache. This is the only setting possible if off-the-record is set or no cache path is available.
QWebEngineProfile::DiskHttpCache 1 Use a disk cache. This is the default.
QWebEngineProfile::NoCache 2 禁用内存和磁盘缓存。(在 Qt 5.7 添加)

enum QWebEngineProfile:: PersistentCookiesPolicy

此枚举描述 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 均保存到磁盘并从中还原。

成员函数文档编制

QWebEngineProfile:: QWebEngineProfile ( QObject * parent = Q_NULLPTR)

构造新 off-the-record 配置文件采用父级 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 ().

QWebEngineProfile:: QWebEngineProfile (const QString & storageName , QObject * parent = Q_NULLPTR)

构造新配置文件采用存储名称 storageName 和父级 parent .

存储名称必须唯一。

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.

另请参阅 storageName ().

QString QWebEngineProfile:: cachePath () const

返回用于缓存的路径。

默认情况下,这在 QStandardPaths::writableLocation () in a storage name specific directory.

另请参阅 setCachePath (), storageName (),和 QStandardPaths::writableLocation ().

清零所有链接从拜访链接数据库。

另请参阅 clearVisitedLinks ().

void QWebEngineProfile:: clearHttpCache ()

移除 Profile 的缓存条目。

该函数在 Qt 5.7 引入。

清零链接在 urls 从拜访链接数据库

另请参阅 clearAllVisitedLinks ().

QWebEngineCookieStore *QWebEngineProfile:: cookieStore ()

返回此配置文件的 Cookie 存储。

该函数在 Qt 5.6 引入。

[static] QWebEngineProfile *QWebEngineProfile:: defaultProfile ()

返回默认配置文件。

默认配置文件使用存储名称 Default。

另请参阅 storageName ().

[signal] void QWebEngineProfile:: downloadRequested ( QWebEngineDownloadItem * download )

此信号被发射每当下载已被触发。 download 自变量保持下载的状态。下载必须被明确接受采用 QWebEngineDownloadItem::accept (),否则默认情况下,它会被取消。下载项的父级是 Profile。若不接受,在信号发出后它会被立即删除。此信号不可以用于队列连接。

该函数在 Qt 5.5 引入。

另请参阅 QWebEngineDownloadItem .

QString QWebEngineProfile:: httpAcceptLanguage () const

返回 Accept-Language HTTP 请求头字段的值。

该函数在 Qt 5.6 引入。

另请参阅 setHttpAcceptLanguage ().

int QWebEngineProfile:: httpCacheMaximumSize () const

返回 HTTP 缓存的最大尺寸,以字节为单位。

将返回 0 若尺寸被自动控制由 QtWebEngine .

另请参阅 setHttpCacheMaximumSize () 和 httpCacheType ().

HttpCacheType QWebEngineProfile:: httpCacheType () const

返回所用 HTTP 缓存类型。

若配置文件为 off-the-record, MemoryHttpCache 被返回。

另请参阅 setHttpCacheType () 和 cachePath ().

QString QWebEngineProfile:: httpUserAgent () const

返回与 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 ().

void QWebEngineProfile:: installUrlSchemeHandler (const QByteArray & scheme , QWebEngineUrlSchemeHandler * handler )

注册处理程序 handler 为自定义 URL 方案 scheme 在配置文件中。

该函数在 Qt 5.6 引入。

bool QWebEngineProfile:: isOffTheRecord () const

返回 true 若这是 off-the-record 配置文件 (离开计算机无记录)。

这将强制 Cookie 和 HTTP 缓存在内存中,但也强制所有其它通常持久数据存储在内存中。

bool QWebEngineProfile:: isSpellCheckEnabled () const

返回 true 若拼写检查器被启用;否则返回 false .

该函数在 Qt 5.8 引入。

另请参阅 setSpellCheckEnabled ().

PersistentCookiesPolicy QWebEngineProfile:: persistentCookiesPolicy () const

返回持久 Cookie 的当前策略。

若配置文件为 off-the-record, NoPersistentCookies 被返回。

另请参阅 setPersistentCookiesPolicy ().

QString QWebEngineProfile:: persistentStoragePath () const

返回用于存储浏览器和 Web 内容持久数据的路径。

持久数据包括:持久 Cookie、HTML5 本地存储、拜访链接。

默认情况下,这在 QStandardPaths::writableLocation () in a storage name specific directory.

另请参阅 setPersistentStoragePath (), storageName (),和 QStandardPaths::writableLocation ().

void QWebEngineProfile:: removeAllUrlSchemeHandlers ()

移除配置文件中安装的所有自定义 URL 方案处理程序。

该函数在 Qt 5.6 引入。

void QWebEngineProfile:: removeUrlScheme (const QByteArray & scheme )

称除自定义 URL 方案 scheme 从配置文件。

该函数在 Qt 5.6 引入。

另请参阅 removeUrlSchemeHandler ().

void QWebEngineProfile:: removeUrlSchemeHandler ( QWebEngineUrlSchemeHandler * handler )

移除自定义 URL 方案处理程序 handler 从配置文件。

该函数在 Qt 5.6 引入。

另请参阅 removeUrlScheme ().

QWebEngineScriptCollection *QWebEngineProfile:: scripts () const

返回注入到共享此配置文件的所有页面中的脚本集合。

另请参阅 QWebEngineScriptCollection , QWebEngineScript ,和 QWebEnginePage::scripts ().

void QWebEngineProfile:: setCachePath (const QString & path )

覆盖用于磁盘缓存的默认路径,将其设为 path .

若设为 null 字符串,则还原默认路径。

另请参阅 cachePath ().

void QWebEngineProfile:: setHttpAcceptLanguage (const QString & httpAcceptLanguage )

把 Accept-Language HTTP 请求头字段值设为 httpAcceptLanguage .

该函数在 Qt 5.6 引入。

另请参阅 httpAcceptLanguage ().

void QWebEngineProfile:: setHttpCacheMaximumSize ( int maxSize )

把 HTTP 缓存的最大尺寸设为 maxSize 字节。

把它设为 0 意味着尺寸将被自动控制由 QtWebEngine .

另请参阅 httpCacheMaximumSize () 和 setHttpCacheType ().

void QWebEngineProfile:: setHttpCacheType ( QWebEngineProfile::HttpCacheType httpCacheType )

把 HTTP 缓存类型设为 httpCacheType .

另请参阅 httpCacheType () 和 setCachePath ().

void QWebEngineProfile:: setHttpUserAgent (const QString & userAgent )

覆盖默认用户代理字符串,将其设为 userAgent .

另请参阅 httpUserAgent ().

void QWebEngineProfile:: setPersistentCookiesPolicy ( QWebEngineProfile::PersistentCookiesPolicy newPersistentCookiesPolicy )

把持久 Cookie 策略设为 newPersistentCookiesPolicy .

另请参阅 persistentCookiesPolicy ().

void QWebEngineProfile:: setPersistentStoragePath (const QString & path )

覆盖用于存储持久 Web 引擎数据的默认路径。

path 设为 null 字符串,则还原默认路径。

另请参阅 persistentStoragePath ().

void QWebEngineProfile:: setRequestInterceptor ( QWebEngineUrlRequestInterceptor * interceptor )

注册请求拦截器单例 interceptor 到拦截 URL 请求。

配置文件不拥有指针的所有权。

该函数在 Qt 5.6 引入。

另请参阅 QWebEngineUrlRequestInfo .

void QWebEngineProfile:: setSpellCheckEnabled ( bool enable )

启用拼写检查器,若 enable is true ,否则禁用它。

该函数在 Qt 5.8 引入。

另请参阅 isSpellCheckEnabled ().

void QWebEngineProfile:: setSpellCheckLanguages (const QStringList & languages )

设置当前列表 languages 为拼写检查器。每种语言应该匹配的名称源于 .bdic 字典。例如,语言 en-US 将加载 en-US.bdic 字典文件。

Qt WebEngine checks for the qtwebengine_dictionaries subdirectory first in the local directory and if it is not found, in the Qt installation directory.

On macOS , depending on how Qt WebEngine is configured at build time, there are two possibilities how spellchecking data is found:

  • Hunspell dictionaries (default) - .bdic dictionaries are used, just like on other platforms
  • Native dictionaries - the macOS spellchecking APIs are used (which means the results will depend on the installed OS dictionaries)

Thus, in the macOS Hunspell case, Qt WebEngine will look in the qtwebengine_dictionaries subdirectory located inside the application bundle 资源 directory, and also in the 资源 directory located inside the Qt framework bundle.

To summarize, in case of Hunspell usage, the following paths are considered:

了解更多信息关于如何编译 .bdic 字典,见 拼写检查器范例 .

该函数在 Qt 5.8 引入。

另请参阅 spellCheckLanguages ().

QWebEngineSettings *QWebEngineProfile:: settings () const

返回在此配置文件中,所有页面的默认设置。

QStringList QWebEngineProfile:: spellCheckLanguages () const

返回拼写检查器所用的语言列表。

该函数在 Qt 5.8 引入。

另请参阅 setSpellCheckLanguages ().

QString QWebEngineProfile:: storageName () const

返回配置文件的存储名称。

存储名称为每个配置文件 (对于持久数据和缓存) 提供使用磁盘的单独子目录。

const QWebEngineUrlSchemeHandler *QWebEngineProfile:: urlSchemeHandler (const QByteArray & scheme ) const

返回自定义 URL 方案的处理程序寄存器,对于 URL 方案 scheme .

该函数在 Qt 5.6 引入。

bool QWebEngineProfile:: visitedLinksContainsUrl (const QUrl & url ) const

返回 true if url 被认为通过此配置文件拜访过链接。