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

WebEngine Widgets Minimal Example

Displays a web page using Qt WebEngine Widgets.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

WebEngine Widgets Minimal Example▲

Image non disponible

https:// Widgets Minimal Example demonstrates how to use https:// to render a web page. It shows the minimum amount of code needed to load and display an HTML page, and can be used as a basis for further experimentation.

Running the Example▲

To run the example from http://, open the Welcome mode and select the example from Examples. For more information, visit http://.

The Code▲

We first define a commandLineUrlArgument function that returns the URL to open. This is either the first positional argument given on the command line, or https://www.qt.io as a fallback.

 
Sélectionnez
#include <QApplication>
#include <QWebEngineView>

QUrl commandLineUrlArgument()
{
    const QStringList args = QCoreApplication::arguments();
    for (const QString &arg : args.mid(1)) {
        if (!arg.startsWith(QLatin1Char('-')))
            return QUrl::fromUserInput(arg);
    }
    return QUrl(QStringLiteral("https://www.qt.io"));
}

In the main function we first set the https:// property. This affects the locations where Qt WebEngine stores persistent and cached data (see also https:// and https://).

We also set the https:// attribute. This lets the web view automatically scale on high-dpi displays.

Next, we instantiate a https:// and a https://. The URL to load is taken from commandLineUrlArgument and loaded by calling https://. The view widget is given a reasonable default size, and shown. Finally, https://() launches the main event loop.

 
Sélectionnez
int main(int argc, char *argv[])
{
    QCoreApplication::setOrganizationName("QtExamples");
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication app(argc, argv);

    QWebEngineView view;
    view.setUrl(commandLineUrlArgument());
    view.resize(1024, 750);
    view.show();

    return app.exec();
}

Requirements▲

The example requires a working internet connection to render the http://. An optional system proxy should be picked up automatically. However, for proxies that require a username or password, you need to connect to https://.

https:// uses the https:// to compose the page. Therefore, OpenGL support is required.

List of Files▲

Files:

List of Files▲

  • webenginewidgets/minimal/main.cpp

  • webenginewidgets/minimal/minimal.pro

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

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.