IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Qt WebEngine QML Types

Provides QML types for rendering web content within a QML application.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

Qt WebEngine QML Types

To link against the module using build with qmake, add the following QT variable to your qmake .pro file:

 
Sélectionnez
QT += webenginequick

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:

 
Sélectionnez
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:

 
Sélectionnez
#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:

 
Sélectionnez
import QtQuick
import QtQuick.Window
import QtWebEngine

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

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+