QWebEngineProfileBuilder Class

QWebEngineProfileBuilder 类提供了一种构建QWebEngineProfile 的方法。更多

头文件: #include <QWebEngineProfileBuilder>
CMake: find_package(Qt6 REQUIRED COMPONENTS WebEngineCore)
target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore)
qmake: QT += webenginecore
Qt 6.9

公共函数

QWebEngineProfile *createProfile(const QString &storageName, QObject *parent = nullptr) const
QWebEngineProfileBuilder &setCachePath(const QString &path)
QWebEngineProfileBuilder &setHttpCacheMaximumSize(int maxSizeInBytes)
QWebEngineProfileBuilder &setHttpCacheType(QWebEngineProfile::HttpCacheType httpCacheType)
QWebEngineProfileBuilder &setPersistentCookiesPolicy(QWebEngineProfile::PersistentCookiesPolicy persistentCookiePolicy)
QWebEngineProfileBuilder &setPersistentPermissionsPolicy(QWebEngineProfile::PersistentPermissionsPolicy persistentPermissionPolicy)
QWebEngineProfileBuilder &setPersistentStoragePath(const QString &path)

静态公共成员

QWebEngineProfile *createOffTheRecordProfile(QObject *parent = nullptr)

详细说明

QWebEngineProfileBuilder 创建QWebEngineProfile 类的一个实例。某些配置文件属性必须在一次调用中初始化,并且在配置文件生命周期内不得修改。网络引擎配置文件生成器会对此进行简单的保护。

成员函数文档

[static] QWebEngineProfile *QWebEngineProfileBuilder::createOffTheRecordProfile(QObject *parent = nullptr)

使用父对象parent 创建一个无记录配置文件,该配置文件不会在本地计算机上留下记录,也没有持久数据或缓存。这将迫使 cookie、持久数据和 HTTP 缓存存储在内存中

QWebEngineProfile *QWebEngineProfileBuilder::createProfile(const QString &storageName, QObject *parent = nullptr) const

构建一个配置文件,存储名称为storageName ,父配置文件为parent

存储名称用于为每个基于磁盘的配置文件提供一个单独的子目录,用于永久数据和缓存。存储位置在应用程序生命周期内必须是唯一的。用户应防止创建具有相同存储位置的配置文件,否则会导致浏览器缓存损坏。

基于磁盘的QWebEngineProfile 应在应用程序退出前销毁,否则缓存和持久数据可能无法完全刷新到磁盘。

注意: 创建基于磁盘的配置文件时,如果数据路径已被其他配置文件使用,函数将返回一个空指针。

另请参阅 QWebEngineProfile::storageName()。

QWebEngineProfileBuilder &QWebEngineProfileBuilder::setCachePath(const QString &path)

将用于缓存的路径设置为path

默认情况下,该路径位于 QtWebengine/StorageName 特定子目录中 StandardPaths::CacheLocation 的下方。

另请参阅 QWebEngineProfile::cachePath() 和QStandardPaths::writableLocation() 。

QWebEngineProfileBuilder &QWebEngineProfileBuilder::setHttpCacheMaximumSize(int maxSizeInBytes)

将 HTTP 缓存的最大大小设置为maxSizeInBytes 字节。

将其设置为0 意味着大小将由QtWebEngine 自动控制。

另请参阅 QWebEngineProfile::httpCacheMaximumSize() 和setHttpCacheType()。

QWebEngineProfileBuilder &QWebEngineProfileBuilder::setHttpCacheType(QWebEngineProfile::HttpCacheType httpCacheType)

将 HTTP 缓存类型设置为httpCacheType

另请参阅 QWebEngineProfile::httpCacheType() 和setCachePath() 。

QWebEngineProfileBuilder &QWebEngineProfileBuilder::setPersistentCookiesPolicy(QWebEngineProfile::PersistentCookiesPolicy persistentCookiePolicy)

将持久性 cookie 的政策设置为persistentCookiePolicy

另请参阅 QWebEngineProfile::persistentCookiesPolicy().

QWebEngineProfileBuilder &QWebEngineProfileBuilder::setPersistentPermissionsPolicy(QWebEngineProfile::PersistentPermissionsPolicy persistentPermissionPolicy)

将持久权限策略设置为persistentPermissionPolicy

另请参阅 QWebEngineProfile::persistentPermissionsPolicy() 。

QWebEngineProfileBuilder &QWebEngineProfileBuilder::setPersistentStoragePath(const QString &path)

将用于存储浏览器和网页内容的持久数据的路径设置为path 。持久数据包括持久 Cookie、HTML5 本地存储和访问过的链接。

默认情况下,该路径位于 QtWebengine/StorageName 特定子目录中的 QStandardPaths::DataLocation 下方。

注: 使用QStandardPaths::writableLocation(QStandardPaths::DataLocation) 获取 QStandardPaths::DataLocation 路径。

另请参阅 QWebEngineProfile::persistentStoragePath() 和QStandardPaths::writableLocation() 。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.