The 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 & 語言 ) |
| 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 () |
The QWebEngineProfile class provides a web engine profile shared by multiple pages.
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 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 網絡堆棧之前。
A QWebEngineUrlSchemeHandler 可以注冊為 Profile (配置文件) 通過 installUrlSchemeHandler () 去添加對自定義 URL 方案的支持。然後把方案請求發送給 QWebEngineUrlSchemeHandler::requestStarted () 作為 QWebEngineUrlRequestJob 對象。
可以啓用每個 Profile (配置文件) 的拼寫檢查 HTML 錶單字段通過使用 setSpellCheckEnabled () 方法和可以設置用於拼寫檢查的當前語言通過使用 setSpellCheckLanguages () 方法。
此枚舉描述 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 添加) |
此枚舉描述 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 均保存到磁盤並從中還原。 |
構造新 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 ().
構造新 Profile (配置文件) 采用存儲名稱 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 ().
返迴用於緩存的路徑。
默認情況下,這在 QStandardPaths::writableLocation () in a storage name specific directory.
另請參閱 setCachePath (), storageName (),和 QStandardPaths::writableLocation ().
清零所有鏈接從拜訪鏈接數據庫。
另請參閱 clearVisitedLinks ().
移除 Profile 的緩存條目。
該函數在 Qt 5.7 引入。
清零鏈接在 urls 從拜訪鏈接數據庫
另請參閱 clearAllVisitedLinks ().
返迴用於此 Profile (配置文件) 的 Cookie 存儲。
該函數在 Qt 5.6 引入。
[static]
QWebEngineProfile
*QWebEngineProfile::
defaultProfile
()
返迴默認 Profile (配置文件)。
默認 Profile (配置文件) 使用 Default 存儲名稱。
另請參閱 storageName ().
[signal]
void
QWebEngineProfile::
downloadRequested
(
QWebEngineDownloadItem
*
download
)
此信號被發射每當下載已被觸發。 download 自變量保持下載的狀態。下載必須被明確接受采用 QWebEngineDownloadItem::accept (),否則默認情況下,它會被取消。下載項的父級是 Profile。若不接受,在信號發齣後它會被立即刪除。此信號不可以用於隊列連接。
該函數在 Qt 5.5 引入。
另請參閱 QWebEngineDownloadItem .
返迴 Accept-Language HTTP 請求頭字段的值。
該函數在 Qt 5.6 引入。
另請參閱 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 (配置文件) 中。
該函數在 Qt 5.6 引入。
返迴
true
若這是 off-the-record Profile 配置文件 (離開計算機無記錄)。
這將強製 Cookie 和 HTTP 緩存在內存中,但也強製所有其它通常持久數據存儲在內存中。
返迴
true
若拼寫檢查器被啓用;否則返迴
false
.
該函數在 Qt 5.8 引入。
另請參閱 setSpellCheckEnabled ().
返迴持久 Cookie 的當前策略。
若 Profile (配置文件) 為 off-the-record, NoPersistentCookies 被返迴。
另請參閱 setPersistentCookiesPolicy ().
返迴用於存儲瀏覽器和 Web 內容持久數據的路徑。
持久數據包括:持久 Cookie、HTML5 本地存儲、拜訪鏈接。
默認情況下,這在 QStandardPaths::writableLocation () in a storage name specific directory.
另請參閱 setPersistentStoragePath (), storageName (),和 QStandardPaths::writableLocation ().
移除 Profile (配置文件) 中安裝的所有自定義 URL 方案處理程序。
該函數在 Qt 5.6 引入。
稱除自定義 URL 方案 scheme 從 Profile (配置文件)。
該函數在 Qt 5.6 引入。
另請參閱 removeUrlSchemeHandler ().
移除自定義 URL 方案處理程序 handler 從 Profile (配置文件)。
該函數在 Qt 5.6 引入。
另請參閱 removeUrlScheme ().
返迴注入到共享此 Profile (配置文件) 的所有頁麵中的腳本集閤。
另請參閱 QWebEngineScriptCollection , QWebEngineScript ,和 QWebEnginePage::scripts ().
覆蓋用於磁盤緩存的默認路徑,將其設為 path .
若設為 null 字符串,則還原默認路徑。
另請參閱 cachePath ().
把 Accept-Language HTTP 請求頭字段值設為 httpAcceptLanguage .
該函數在 Qt 5.6 引入。
另請參閱 httpAcceptLanguage ().
把 HTTP 緩存的最大尺寸設為 maxSize 字節。
把它設為
0
意味著尺寸將被自動控製由
QtWebEngine
.
另請參閱 httpCacheMaximumSize () 和 setHttpCacheType ().
把 HTTP 緩存類型設為 httpCacheType .
另請參閱 httpCacheType () 和 setCachePath ().
覆寫默認用戶代理字符串,將其設為 userAgent .
另請參閱 httpUserAgent ().
把持久 Cookie 策略設為 newPersistentCookiesPolicy .
另請參閱 persistentCookiesPolicy ().
覆蓋用於存儲持久 Web 引擎數據的默認路徑。
若 path 設為 null 字符串,則還原默認路徑。
另請參閱 persistentStoragePath ().
注冊請求攔截器單例 interceptor 到攔截 URL 請求。
Profile (配置文件) 不擁有指針的所有權。
該函數在 Qt 5.6 引入。
另請參閱 QWebEngineUrlRequestInfo .
啓用拼寫檢查器,若
enable
is
true
,否則禁用它。
該函數在 Qt 5.8 引入。
另請參閱 isSpellCheckEnabled ().
設置當前列錶
語言
為拼寫檢查器。每種語言應該匹配的名稱源於
.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:
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 ().
返迴此 Profile (配置文件) 中所有頁麵的默認設置。
返迴拼寫檢查器所用的語言列錶。
該函數在 Qt 5.8 引入。
另請參閱 setSpellCheckLanguages ().
返迴 Profile (配置文件) 的存儲名稱。
存儲名稱為每個 Profile 配置文件 (對於持久數據和緩存) 提供使用磁盤的單獨子目錄。
返迴自定義 URL 方案的處理程序寄存器,對於 URL 方案 scheme .
該函數在 Qt 5.6 引入。
返迴
true
if
url
被認為通過此 Profile (配置文件) 拜訪過鏈接。