Qt WebEngine QML 類型

要鏈接到采用 qmake 構建的模塊,添加以下 QT 變量到 qmake .pro 文件:

QT += webenginequick
						

為采用 CMake 構建,使用 find_package() 命令以定位 Qt6 包中需要的模塊組件和 target_link_libraries() 以鏈接到模塊:

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

The minimal amount of code needed to load and display an HTML page using the QML engine requires a proper initialization:

#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();
}
						

Where the content of main.qml is simply:

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

A request for providing authentication credentials required by proxies or HTTP servers

ColorDialogRequest

用於通過用戶選擇顔色的請求

ContextMenuRequest

用於展示上下文菜單的請求

FileDialogRequest

A request for letting the user choose a (new or existing) file or directory

FindTextResult

A utility type for encapsulating the result of a string search on a page

FullScreenRequest

A utility type for the WebEngineView::fullScreenRequested() signal

JavaScriptDialogRequest

A request for showing an alert, a confirmation, or a prompt dialog from within JavaScript to the user

RegisterProtocolHandlerRequest

Type enables accepting or rejecting requests from the registerProtocolHandler API

TooltipRequest

A request for showing a tooltip to the user

TouchSelectionMenuRequest

A request for showing a touch selection menu

WebEngine

Provides access to the default settings and profiles shared by all web engine views

WebEngineAction

An action that represents a WebEngineView::WebAction

WebEngineCertificateError

A utility type for ignoring certificate errors or rejecting erroneous certificates

WebEngineClientCertificateOption

Represents a client certificate option

WebEngineClientCertificateSelection

Provides a selection of client certificates

WebEngineDownloadRequest

提供下載的有關信息

WebEngineHistory

Provides data models that represent the history of a web engine page

WebEngineHistoryModel

A data model that represents the history of a web engine page

WebEngineLoadingInfo

A utility type for the WebEngineView::loadingChanged signal

WebEngineNavigationRequest

Represents a request for navigating to a web page as part of WebEngineView::navigationRequested()

WebEngineNewWindowRequest

A utility type for the WebEngineView::newWindowRequested signal

WebEngineNotification

封裝 HTML5 Web 通知數據

WebEngineProfile

Contains settings, scripts, and visited links common to multiple web engine views

WebEngineProfilePrototype

Creates an instance of QQuickWebEngineProfile class

WebEngineScriptCollection

Manages a collection of user scripts

WebEngineSettings

Allows configuration of browser properties and attributes

WebEngineView

A WebEngineView renders web content within a QML application

WebEngineWebAuthUxRequest

Encapsulates the data of a WebAuth UX request

QML 值類型

webEngineDesktopMediaRequest

A request for populating a dialog with available sources for screen capturing

webEngineFrame

Information about and control over a page frame

webEnginePermission

An object used to access and modify the state of a single permission that's been granted or denied to a specific origin URL

webEngineScript

Enables the programmatic injection of scripts in the JavaScript engine

webEngineWebAuthPinRequest

Encapsulates the data of a PIN WebAuth UX request