Qt WebEngine QML Types

要使用 qmake 联编模块,请在 qmake .pro 文件中添加以下 QT 变量:

QT += webenginequick

使用 CMake 构建时,可使用find_package() 命令在 Qt6 软件包中找到所需的模块组件,然后使用target_link_libraries() 链接模块:

find_package(Qt6 REQUIRED COMPONENTS WebEngineQuick)
target_link_libraries(target PRIVATE Qt6::WebEngineQuick)

使用 QML 引擎加载和显示 HTML 页面所需的代码量极少,因此需要适当的初始化:

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtWebEngineQuick/qtwebenginequickglobal.h>

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
    QtWebEngineQuick::initialize();
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    return app.exec();
}

其中 main.qml 的内容非常简单:

import QtQuick
import QtQuick.Window
import QtWebEngine

Window {
    width: 1024
    height: 750
    visible: true
    WebEngineView {
        anchors.fill: parent
        url: "https://www.qt.io"
    }
}

QML 对象类型

AuthenticationDialogRequest

提供代理或 HTTP 服务器所需的身份验证凭据的请求

ColorDialogRequest

用户选择颜色的请求

ContextMenuRequest

显示上下文菜单的请求

FileDialogRequest

让用户选择(新的或现有的)文件或目录的请求

FindTextResult

用于在页面上封装字符串搜索结果的实用程序类型

FullScreenRequest

用于 WebEngineView::fullScreenRequested() 信号的实用程序类型

JavaScriptDialogRequest

用于在 JavaScript 中向用户显示警报、确认或提示对话框的请求

RegisterProtocolHandlerRequest

用于接受或拒绝 registerProtocolHandler API 请求的类型

TooltipRequest

向用户显示工具提示的请求

TouchSelectionMenuRequest

显示触摸选择菜单的请求

WebEngine

访问所有网络引擎视图共享的默认设置和配置文件

WebEngineAction

表示 WebEngineView::WebAction 的动作

WebEngineCertificateError

用于忽略证书错误或拒绝错误证书的实用程序类型

WebEngineClientCertificateOption

代表客户证书选项

WebEngineClientCertificateSelection

提供客户证书选择

WebEngineDesktopMediaRequest

请求在对话框中填充可用的屏幕捕获源

WebEngineDownloadRequest

提供有关下载的信息

WebEngineHistory

提供表示网络引擎页面历史的数据模型

WebEngineHistoryModel

表示网络引擎页面历史的数据模型

WebEngineLoadingInfo

用于 WebEngineView::loadingChanged 信号的实用程序类型

WebEngineNavigationRequest

表示导航到网页的请求,是 WebEngineView::navigationRequested() 的一部分

WebEngineNewWindowRequest

WebEngineView::newWindowRequested 信号的实用程序类型

WebEngineNotification

封装 HTML5 网页通知的数据

WebEngineProfile

包含多个网络引擎视图共有的设置、脚本和访问链接

WebEngineProfilePrototype

创建 QQuickWebEngineProfile 类的实例

WebEngineScript

在JavaScript引擎中以编程方式注入脚本

WebEngineScriptCollection

管理用户脚本集合

WebEngineSettings

允许配置浏览器属性

WebEngineView

WebEngineView在QML应用程序中渲染网页内容

WebEngineWebAuthUxRequest

封装 WebAuth UX 请求的数据

QML 值类型

webEngineFrame

页面框架的信息和控制

webEnginePermission

用于访问和修改已授予或拒绝特定起源 URL 的单个权限状态的对象

webEngineWebAuthPinRequest

封装 PIN WebAuth UX 请求的数据

© 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.