1 /****************************************************************************
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
6 ** This file is part of the documentation of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:FDL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
17 ** GNU Free Documentation License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Free
19 ** Documentation License version 1.3 as published by the Free Software
20 ** Foundation and appearing in the file included in the packaging of
21 ** this file. Please review the following information to ensure
22 ** the GNU Free Documentation License version 1.3 requirements
23 ** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
26 ****************************************************************************/
29 \example webengine/minimal
30 \title WebEngine Qt Quick Minimal Example
31 \ingroup webengine-examples
32 \brief Displays a web page using the Qt Quick integration of Qt WebEngine
34 \image minimal-example.png
36 \e {WebEngine Qt Quick Minimal Example} demonstrates how to use the
37 \l{WebEngineView} item to render a web page. It shows the minimum amount of
38 code needed to load and display an HTML page, and can be used as a basis for
39 further experimentation.
41 \include examples-run.qdocinc
45 In \c main.cpp we use only the QGuiApplication and QQmlApplicationEngine
46 classes. We also include \c qtwebengineglobal.h to be able to use
47 \l{QtWebEngine::initialize}.
49 \quotefromfile webengine/minimal/main.cpp
53 In the \c main function we first set the Qt::AA_EnableHighDpiScaling
54 attribute. This lets the web view automatically scale on high-dpi displays.
55 Then we instantiate a QGuiApplication object.
57 Next, we call \l{QtWebEngine::initialize}, which makes sure that OpenGL
58 contexts can be shared between the main process and the dedicated renderer
59 process (\c QtWebEngineProcess). This method needs to be called before
60 any OpenGL context is created.
62 Then we create a QQmlApplicationEngine, and tell it to load \c main.qml
63 from the \l{The Qt Resource System}{Qt Resource System}.
65 Finally, QGuiApplication::exec() launches the main event loop.
71 In \c main.qml we create the top level window, set a sensible default size
72 and make it visible. The window will be filled by a WebEngineView item
73 loading the \l{Qt Homepage}.
75 \quotefromfile webengine/minimal/main.qml
80 \section1 Requirements
82 The example requires a working internet connection to render the
84 An optional system proxy should be picked up automatically.