Qt WebEngine QML Types | Qt WebEngine (original) (raw)
To link against the module using build with qmake, add the following QT variable to your qmake .pro file:
For build with CMake use the find_package()
command to locate the needed module components in the Qt6 package and target_link_libraries()
to link against the module:
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 #include #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" } }