The QQuickWebEngineProfile class provides a web engine profile shared by multiple pages. 更多...
| 頭: |
#include <QQuickWebEngineProfile>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS WebEngineQuick)
target_link_libraries(mytarget PRIVATE Qt6::WebEngineQuick)
|
| qmake: |
QT += webenginequick
|
| 在 QML: | WebEngineProfile |
| 繼承: | QObject |
| enum | HttpCacheType { MemoryHttpCache, DiskHttpCache, NoCache } |
| enum | PersistentCookiesPolicy { NoPersistentCookies, AllowPersistentCookies, ForcePersistentCookies } |
(從 6.8 起)
枚舉類
|
PersistentPermissionsPolicy { AskEveryTime, StoreInMemory, StoreOnDisk } |
|
|
| QQuickWebEngineProfile (QObject * parent = nullptr) | |
| QString | cachePath () const |
| void | clearHttpCache () |
| QWebEngineClientCertificateStore * | clientCertificateStore () |
(從 6.8 起)
QWebEngineClientHints *
|
clientHints () const |
| QWebEngineCookieStore * | cookieStore () const |
| QString | downloadPath () const |
| QString | httpAcceptLanguage () const |
| int | httpCacheMaximumSize () const |
| QQuickWebEngineProfile::HttpCacheType | httpCacheType () const |
| QString | httpUserAgent () const |
| void | installUrlSchemeHandler (const QByteArray & scheme , QWebEngineUrlSchemeHandler * handler ) |
| bool | isOffTheRecord () const |
| 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 |
| QQuickWebEngineProfile::PersistentCookiesPolicy | persistentCookiesPolicy () const |
| QQuickWebEngineProfile::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 ) |
| void | setCachePath (const QString & path ) |
| void | setDownloadPath (const QString & path ) |
| void | setHttpAcceptLanguage (const QString & httpAcceptLanguage ) |
| void | setHttpCacheMaximumSize (int maxSize ) |
| void | setHttpCacheType (QQuickWebEngineProfile::HttpCacheType) |
| void | setHttpUserAgent (const QString & userAgent ) |
| void | setOffTheRecord (bool offTheRecord ) |
| void | setPersistentCookiesPolicy (QQuickWebEngineProfile::PersistentCookiesPolicy) |
| void | setPersistentPermissionsPolicy (QQuickWebEngineProfile::PersistentPermissionsPolicy) |
| void | setPersistentStoragePath (const QString & path ) |
| void | setPushServiceEnabled (bool enable ) |
| void | setSpellCheckEnabled (bool enabled ) |
| void | setSpellCheckLanguages (const QStringList & 語言 ) |
| void | setStorageName (const QString & name ) |
| void | setUrlRequestInterceptor (QWebEngineUrlRequestInterceptor * interceptor ) |
| QStringList | spellCheckLanguages () const |
| QString | storageName () const |
| const QWebEngineUrlSchemeHandler * | urlSchemeHandler (const QByteArray & scheme ) const |
| QQuickWebEngineScriptCollection * | userScripts () const |
| void | cachePathChanged () |
(從 6.7 起)
void
|
clearHttpCacheCompleted () |
| void | downloadFinished (QQuickWebEngineDownloadRequest * download ) |
| void | downloadPathChanged () |
| void | downloadRequested (QQuickWebEngineDownloadRequest * download ) |
| void | httpAcceptLanguageChanged () |
| void | httpCacheMaximumSizeChanged () |
| void | httpCacheTypeChanged () |
| void | httpUserAgentChanged () |
| void | offTheRecordChanged () |
| void | persistentCookiesPolicyChanged () |
| void | persistentPermissionsPolicyChanged () |
| void | persistentStoragePathChanged () |
| void | presentNotification (QWebEngineNotification * notification ) |
| void | pushServiceEnabledChanged () |
| void | spellCheckEnabledChanged () |
| void | spellCheckLanguagesChanged () |
| void | storageNameChanged () |
| QQuickWebEngineProfile * | defaultProfile () |
Web 引擎 Profile (配置文件) 包含設置、腳本、持久性 Cookie 策略及屬於 Profile 由所有 Web 引擎頁麵共享的拜訪鏈接列錶。
Information about visited links is stored together with persistent cookies and other persistent data in a storage determined by the storageName property. Persistent data is stored in a subdirectory determined by the persistentStoragePath property and the cache in a subdirectory determined by the cachePath property. The httpCacheType property describes the type of the cache: in-memory or on-disk . If only the storageName property is set, the other values are generated automatically based on it. If you specify any of the values manually, you should do it before creating any pages that belong to the profile.
Profiles can be used to isolate pages from each other. A typical use case is a dedicated off-the-record profile 對於 隱私瀏覽 mode. An off-the-record profile forces cookies, the HTTP cache, and other normally persistent data to be stored only in memory. The offTheRecord property holds 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.
A WebEngineProfile instance can be created and accessed from C++ through the QQuickWebEngineProfile class, which exposes further functionality in C++. This allows Qt Quick applications to intercept URL requests (QQuickWebEngineProfile::setRequestInterceptor), or register custom URL schemes ( QQuickWebEngineProfile::installUrlSchemeHandler ).
Spellchecking HTML form fields can be enabled per profile by setting the spellCheckEnabled property and the current languages used for spellchecking can be set by using the spellCheckLanguages 特性。
此枚舉描述 HTTP 緩存類型:
| 常量 | 值 | 描述 |
|---|---|---|
QQuickWebEngineProfile::MemoryHttpCache
|
0
|
使用內存中的緩存。這是默認設置若
off-the-record
有設置。
|
QQuickWebEngineProfile::DiskHttpCache
|
1
|
Use a disk cache. This is the default if
off-the-record
is not set. Falls back to
MemoryHttpCache
if
off-the-record
有設置。
|
QQuickWebEngineProfile::NoCache
|
2
|
禁用內存和磁盤緩存。(在 Qt 5.7 添加) |
此枚舉描述 Cookie 持久性策略:
| 常量 | 值 | 描述 |
|---|---|---|
QQuickWebEngineProfile::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.
|
QQuickWebEngineProfile::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. |
QQuickWebEngineProfile::ForcePersistentCookies
|
2
|
會話和持久 Cookie 均保存到磁盤並從中還原。 |
[since 6.8]
enum class QQuickWebEngineProfile::
PersistentPermissionsPolicy
This enum describes the policy for permission persistence:
| 常量 | 值 | 描述 |
|---|---|---|
QQuickWebEngineProfile::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. |
QQuickWebEngineProfile::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
QQuickWebEngineProfile
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.
|
QQuickWebEngineProfile::PersistentPermissionsPolicy::StoreOnDisk
|
2
|
Works the same way as
PersistentPermissionsInMemory
, but the permissions are saved to and restored from disk. This is the default setting.
|
該枚舉在 Qt 6.8 引入。
The path to the location where the profile's caches are stored, in particular the HTTP cache.
By default, the caches are stored below QStandardPaths::writableLocation ( QStandardPaths::CacheLocation ) in a directory named using storageName .
訪問函數:
| QString | cachePath () const |
| void | setCachePath (const QString & path ) |
通知程序信號:
| void | cachePathChanged () |
[since QtWebEngine 1.9]
downloadPath
:
QString
下載文件存儲位置的路徑。
覆蓋用於下載位置的默認路徑,將其設為 path .
If set to an empty string, the default path is restored.
注意: 默認情況下,下載路徑為 QStandardPaths::DownloadLocation .
This property was introduced in QtWebEngine 1.9.
訪問函數:
| QString | downloadPath () const |
| void | setDownloadPath (const QString & path ) |
通知程序信號:
| void | downloadPathChanged () |
The value of the Accept-Language HTTP request-header field.
訪問函數:
| QString | httpAcceptLanguage () const |
| void | setHttpAcceptLanguage (const QString & httpAcceptLanguage ) |
通知程序信號:
| void | httpAcceptLanguageChanged () |
The maximum size of the HTTP cache. If
0
, the size will be controlled automatically by
QtWebEngine
。默認值為
0
.
訪問函數:
| int | httpCacheMaximumSize () const |
| void | setHttpCacheMaximumSize (int maxSize ) |
通知程序信號:
| void | httpCacheMaximumSizeChanged () |
另請參閱 httpCacheType .
This enumeration describes the type of the HTTP cache.
If the profile is off-the-record or has no storageName set, MemoryHttpCache 被返迴。
訪問函數:
| QQuickWebEngineProfile::HttpCacheType | httpCacheType () const |
| void | setHttpCacheType (QQuickWebEngineProfile::HttpCacheType) |
通知程序信號:
| void | httpCacheTypeChanged () |
The user-agent string sent with HTTP to identify the browser.
訪問函數:
| QString | httpUserAgent () const |
| void | setHttpUserAgent (const QString & userAgent ) |
通知程序信號:
| void | httpUserAgentChanged () |
[since QtWebEngine 6.5]
isPushServiceEnabled
:
bool
Whether the push messaging service is enabled.
注意: By default the push messaging service is disabled.
注意: Qt WebEngine uses the Firebase Cloud Messaging (FCM) as a browser push service. Therefore, all push messages will go through the Google push service and its respective servers.
This property was introduced in QtWebEngine 6.5.
訪問函數:
| bool | isPushServiceEnabled () const |
| void | setPushServiceEnabled (bool enable ) |
通知程序信號:
| void | pushServiceEnabledChanged () |
Whether the web engine profile is off-the-record . An off-the-record profile forces cookies, the HTTP cache, and other normally persistent data to be stored only in memory. Profile is off-the-record by default.
Changing a profile from off-the-record to disk-based behavior also requires setting a proper storageName .
訪問函數:
| bool | isOffTheRecord () const |
| void | setOffTheRecord (bool offTheRecord ) |
通知程序信號:
| void | offTheRecordChanged () |
另請參閱 setStorageName ().
This enumeration describes the policy of cookie persistency. If the profile is off-the-record, NoPersistentCookies 被返迴。
訪問函數:
| QQuickWebEngineProfile::PersistentCookiesPolicy | persistentCookiesPolicy () const |
| void | setPersistentCookiesPolicy (QQuickWebEngineProfile::PersistentCookiesPolicy) |
通知程序信號:
| void | persistentCookiesPolicyChanged () |
[since 6.8]
persistentPermissionsPolicy
:
PersistentPermissionsPolicy
Describes the policy of permission persistence. If the profile is off-the-record, NoPersistentCookies 被返迴。
該特性在 Qt 6.8 引入。
訪問函數:
| QQuickWebEngineProfile::PersistentPermissionsPolicy | persistentPermissionsPolicy () const |
| void | setPersistentPermissionsPolicy (QQuickWebEngineProfile::PersistentPermissionsPolicy) |
通知程序信號:
| void | persistentPermissionsPolicyChanged () |
The path to the location where the persistent data for the browser and web content are stored. Persistent data includes persistent cookies, HTML5 local storage, and visited links.
By default, the storage is located below QStandardPaths::writableLocation ( QStandardPaths::AppDataLocation ) in a directory named using storageName .
訪問函數:
| QString | persistentStoragePath () const |
| void | setPersistentStoragePath (const QString & path ) |
通知程序信號:
| void | persistentStoragePathChanged () |
[since QtWebEngine 1.4]
spellCheckEnabled
:
bool
This property holds whether the web engine spell checker is enabled.
This property was introduced in QtWebEngine 1.4.
訪問函數:
| bool | isSpellCheckEnabled () const |
| void | setSpellCheckEnabled (bool enabled ) |
通知程序信號:
| void | spellCheckEnabledChanged () |
[since QtWebEngine 1.4]
spellCheckLanguages
:
QStringList
This property holds the languages used by the spell checker.
This property was introduced in QtWebEngine 1.4.
訪問函數:
| QStringList | spellCheckLanguages () const |
| void | setSpellCheckLanguages (const QStringList & 語言 ) |
通知程序信號:
| void | spellCheckLanguagesChanged () |
The storage name that is used to create separate subdirectories for each profile that uses the disk for storing persistent data and cache.
訪問函數:
| QString | storageName () const |
| void | setStorageName (const QString & name ) |
通知程序信號:
| void | storageNameChanged () |
另請參閱 persistentStoragePath and cachePath .
構造新 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.
[invokable]
void
QQuickWebEngineProfile::
clearHttpCache
()
移除 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.
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
另請參閱 WebEngineProfile::clearHttpCache () 和 clearHttpCacheCompleted ().
[signal, since 6.7]
void
QQuickWebEngineProfile::
clearHttpCacheCompleted
()
此信號發射,當 clearHttpCache () operation is completed.
該函數在 Qt 6.7 引入。
另請參閱 clearHttpCache ().
返迴 Profile (配置文件) 的客戶端證書存儲。
[since 6.8]
QWebEngineClientHints
*QQuickWebEngineProfile::
clientHints
() const
Return the Client Hints settings associated with this browsing context.
注意: Getter function for property clientHints.
該函數在 Qt 6.8 引入。
另請參閱 QWebEngineClientHints .
返迴用於此 Profile (配置文件) 的 Cookie 存儲。
[static]
QQuickWebEngineProfile
*QQuickWebEngineProfile::
defaultProfile
()
返迴默認 Profile (配置文件)。
The default profile is off-the-record.
另請參閱 storageName ().
[signal]
void
QQuickWebEngineProfile::
downloadFinished
(
QQuickWebEngineDownloadRequest
*
download
)
This signal is emitted whenever downloading stops, because it finished successfully, was cancelled, or was interrupted (for example, because connectivity was lost). The download argument holds the state of the finished download instance.
注意: To use from C++ static_cast download to QWebEngineDownloadRequest
[signal]
void
QQuickWebEngineProfile::
downloadRequested
(
QQuickWebEngineDownloadRequest
*
download
)
此信號被發射每當下載已被觸發。
download
自變量保持下載的狀態。下載必須被明確接受采用
QWebEngineDownloadRequest::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.
注意: To use from C++ static_cast download to QWebEngineDownloadRequest
注冊處理程序 handler 為自定義 URL 方案 scheme 在 Profile (配置文件) 中。
它是必要的,首先注冊方案采用 QWebEngineUrlScheme::registerScheme 在應用程序啓動時。
[invokable, since 6.8]
QList
<
QWebEnginePermission
> QQuickWebEngineProfile::
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
這將返迴空列錶。
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
該函數在 Qt 6.8 引入。
另請參閱 queryPermission (), listPermissionsForOrigin (), listPermissionsForPermissionType (),和 QWebEnginePermission::isPersistent ().
[invokable, since 6.8]
QList
<
QWebEnginePermission
> QQuickWebEngineProfile::
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/.
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
該函數在 Qt 6.8 引入。
另請參閱 queryPermission (), listAllPermissions (), listPermissionsForPermissionType (),和 QWebEnginePermission::isPersistent ().
[invokable, since 6.8]
QList
<
QWebEnginePermission
> QQuickWebEngineProfile::
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
這將返迴空列錶。
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
該函數在 Qt 6.8 引入。
另請參閱 queryPermission (), listAllPermissions (), listPermissionsForOrigin (), QWebEnginePermission::PermissionType ,和 QWebEnginePermission::isPersistent ().
[signal]
void
QQuickWebEngineProfile::
presentNotification
(
QWebEngineNotification
*
notification
)
This signal is emitted whenever there is a newly created user notification. The notification argument holds the QWebEngineNotification instance to query data and interact with.
另請參閱 WebEngineProfile::presentNotification .
[invokable, since 6.8]
QWebEnginePermission
QQuickWebEngineProfile::
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.
注意: This may only be used for persistent permission types. Calling it with a non-persistent permissionType will return an invalid object.
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
該函數在 Qt 6.8 引入。
另請參閱 listAllPermissions (), listPermissionsForOrigin (), listPermissionsForPermissionType (),和 QWebEnginePermission::PermissionType .
移除 Profile (配置文件) 中安裝的所有自定義 URL 方案處理程序。
稱除自定義 URL 方案 scheme 從 Profile (配置文件)。
另請參閱 removeUrlSchemeHandler ().
移除自定義 URL 方案處理程序 handler 從 Profile (配置文件)。
另請參閱 removeUrlScheme ().
注冊請求攔截器單例 interceptor 到攔截 URL 請求。
Profile (配置文件) 不擁有指針的所有權。
另請參閱 QWebEngineUrlRequestInfo and QWebEngineUrlRequestInterceptor .
返迴拼寫檢查器所用的語言列錶。
注意: Getter function for property spellCheckLanguages.
另請參閱 setSpellCheckLanguages ().
返迴自定義 URL 方案的處理程序寄存器,對於 URL 方案 scheme .