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 } |
(從 6.8 起)
枚舉類
|
PersistentPermissionsPolicy { AskEveryTime, StoreInMemory, StoreOnDisk } |
| 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 () |
(從 6.8 起)
QWebEngineClientHints *
|
clientHints () const |
| 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 |
(從 6.5 起)
bool
|
isPushServiceEnabled () const |
| bool | isSpellCheckEnabled () const |
(從 6.8 起)
QList<QWebEnginePermission>
|
listAllPermissions () const |
(從 6.8 起)
QList<QWebEnginePermission>
|
listPermissionsForOrigin (const QUrl & securityOrigin ) const |
(從 6.8 起)
QList<QWebEnginePermission>
|
listPermissionsForPermissionType (QWebEnginePermission::PermissionType permissionType ) const |
| QWebEngineProfile::PersistentCookiesPolicy | persistentCookiesPolicy () const |
(從 6.8 起)
QWebEngineProfile::PersistentPermissionsPolicy
|
persistentPermissionsPolicy () const |
| QString | persistentStoragePath () const |
(從 6.8 起)
QWebEnginePermission
|
queryPermission (const QUrl & securityOrigin , QWebEnginePermission::PermissionType permissionType ) const |
| void | removeAllUrlSchemeHandlers () |
| void | removeUrlScheme (const QByteArray & scheme ) |
| void | removeUrlSchemeHandler (QWebEngineUrlSchemeHandler * handler ) |
(從 6.2 起)
void
|
requestIconForIconURL (const QUrl & url , int desiredSizeInPixel , std::function<void (const QIcon &, const QUrl &)> iconAvailableCallback ) const |
(從 6.2 起)
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 ) |
(從 6.8 起)
void
|
setPersistentPermissionsPolicy (QWebEngineProfile::PersistentPermissionsPolicy newPersistentPermissionsPolicy ) |
| void | setPersistentStoragePath (const QString & path ) |
(從 6.5 起)
void
|
setPushServiceEnabled (bool enable ) |
| void | setSpellCheckEnabled (bool enable ) |
| void | setSpellCheckLanguages (const QStringList & 語言 ) |
| 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 |
(從 6.7 起)
void
|
clearHttpCacheCompleted () |
| 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 添加) |
This enum describes policy for cookie persistence:
| 常量 | 值 | 描述 |
|---|---|---|
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 均保存到磁盤並從中還原。 |
[since 6.8]
enum class QWebEngineProfile::
PersistentPermissionsPolicy
This enum describes the policy for permission persistence:
| 常量 | 值 | 描述 |
|---|---|---|
QWebEngineProfile::PersistentPermissionsPolicy::AskEveryTime
|
0
|
The application will ask for permissions every time they're needed, regardless of whether they've been granted before or not. This is intended for backwards compatibility with existing applications, and otherwise not recommended. |
QWebEngineProfile::PersistentPermissionsPolicy::StoreInMemory
|
1
|
A request will be made only the first time a permission is needed. Any subsequent requests will be automatically granted or denied, depending on the initial user choice. This carries over to all pages that use the same
QWebEngineProfile
instance, until the application is shut down. This is the setting applied if
off-the-record
is set or no persistent data path is available.
|
QWebEngineProfile::PersistentPermissionsPolicy::StoreOnDisk
|
2
|
Works the same way as
StoreInMemory
, but the permissions are saved to and restored from disk. This is the default setting.
|
該枚舉在 Qt 6.8 引入。
[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 的緩存條目。
注意: Make sure that you do not start new navigation or any operation on the profile while the clear operation is in progress. The clearHttpCacheCompleted () signal notifies about the completion.
另請參閱 QWebEngineProfile::clearHttpCacheCompleted ().
[signal, since 6.7]
void
QWebEngineProfile::
clearHttpCacheCompleted
()
此信號發射,當 clearHttpCache () operation is completed.
該函數在 Qt 6.7 引入。
另請參閱 QWebEngineProfile::clearHttpCache ().
清零鏈接在 urls 從拜訪鏈接數據庫
另請參閱 clearAllVisitedLinks ().
返迴 Profile (配置文件) 的客戶端證書存儲。
[since 6.8]
QWebEngineClientHints
*QWebEngineProfile::
clientHints
() const
Return the Client Hints settings associated with this browsing context.
該函數在 Qt 6.8 引入。
另請參閱 QWebEngineClientHints .
返迴用於此 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 () 和 Windows Application Manifest .
注冊處理程序 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 ().
[since 6.8]
QList
<
QWebEnginePermission
> QWebEngineProfile::
listAllPermissions
() const
返迴 QList of QWebEnginePermission objects, each one representing a single permission currently present in the permissions store. The returned list contains all previously granted/denied permissions for this profile, provided they are of a persistent 類型。
注意:
當把 persistentPermissionPolicy() 設為
AskEveryTime
這將返迴空列錶。
該函數在 Qt 6.8 引入。
另請參閱 queryPermission (), QWebEnginePermission::PermissionType ,和 QWebEnginePermission::isPersistent ().
[since 6.8]
QList
<
QWebEnginePermission
> QWebEngineProfile::
listPermissionsForOrigin
(const
QUrl
&
securityOrigin
) const
返迴 QList of QWebEnginePermission objects, each one representing a single permission currently present in the permissions store. The returned list contains all previously granted/denied permissions associated with a specific securityOrigin for this profile, provided they are of a persistent 類型。
注意: Since permissions are granted on a per-origin basis, the provided securityOrigin will be stripped to its origin form, and the returned list will contain all permissions for the origin. Thus, passing https://www.example.com/some/page.html is the same as passing just https://www.example.com/.
注意:
當把 persistentPermissionPolicy() 設為
AskEveryTime
這將返迴空列錶。
該函數在 Qt 6.8 引入。
另請參閱 queryPermission (), QWebEnginePermission::PermissionType ,和 QWebEnginePermission::isPersistent ().
[since 6.8]
QList
<
QWebEnginePermission
> QWebEngineProfile::
listPermissionsForPermissionType
(
QWebEnginePermission::PermissionType
permissionType
) const
返迴 QList of QWebEnginePermission objects, each one representing a single permission currently present in the permissions store. The returned list contains all previously granted/denied permissions of the provided permissionType . If the permissionType is non-persistent, the list will be empty.
注意:
當把 persistentPermissionPolicy() 設為
AskEveryTime
這將返迴空列錶。
該函數在 Qt 6.8 引入。
另請參閱 queryPermission (), QWebEnginePermission::PermissionType ,和 QWebEnginePermission::isPersistent ().
返迴持久 Cookie 的當前策略。
若 Profile (配置文件) 為 off-the-record, NoPersistentCookies 被返迴。
另請參閱 setPersistentCookiesPolicy ().
[since 6.8]
QWebEngineProfile::PersistentPermissionsPolicy
QWebEngineProfile::
persistentPermissionsPolicy
() const
Returns the current policy for persistent permissions.
Off-the-record profiles are not allowed to save data to the disk, so they can only return
StoreInMemory
or
AskEveryTime
.
該函數在 Qt 6.8 引入。
另請參閱 QWebEngineProfile::PersistentPermissionsPolicy and setPersistentPermissionsPolicy ().
返迴用於存儲瀏覽器和 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 ().
[since 6.8]
QWebEnginePermission
QWebEngineProfile::
queryPermission
(const
QUrl
&
securityOrigin
,
QWebEnginePermission::PermissionType
permissionType
) const
返迴 QWebEnginePermission object corresponding to a single permission for the provided securityOrigin and permissionType . The object may be used to query for the current state of the permission, or to change it. It is not required for a permission to already exist; the returned object may also be used to pre-grant a permission if a website is known to use it.
You may use this to pre-grant a permission of a non-persistent type. Doing so will keep the permission in the granted (or denied) state until the next time a website with the associated origin requests it. At that point, the permission's lifetime will be tied to that specific web page's lifetime, and navigating away will invalidate the permission.
該函數在 Qt 6.8 引入。
另請參閱 listAllPermissions (), listPermissionsForOrigin (), listPermissionsForPermissionType (),和 QWebEnginePermission::PermissionType .
移除 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 to NoCache on the profile, which has already some cache entries does not trigger the removal of those entries.
另請參閱 httpCacheType (), setCachePath (),和 clearHttpCache ().
覆寫默認用戶代理字符串,將其設為 userAgent .
另請參閱 httpUserAgent ().
設置函數 notificationPresenter 負責呈現已發送通知。
另請參閱 QWebEngineNotification .
把持久 Cookie 策略設為 newPersistentCookiesPolicy .
另請參閱 persistentCookiesPolicy ().
[since 6.8]
void
QWebEngineProfile::
setPersistentPermissionsPolicy
(
QWebEngineProfile::PersistentPermissionsPolicy
newPersistentPermissionsPolicy
)
Sets the policy for persistent permissions to newPersistentPermissionsPolicy .
該函數在 Qt 6.8 引入。
另請參閱 QWebEngineProfile::PersistentPermissionsPolicy and persistentPermissionsPolicy ().
覆蓋用於存儲持久 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 (配置文件) 拜訪過鏈接。