]> rtime.felk.cvut.cz Git - coffee/mtbrowser.git/blob - doc/src/minimal.qdoc
qtwebengine minimal example
[coffee/mtbrowser.git] / doc / src / minimal.qdoc
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
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.
16 **
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.
24 ** $QT_END_LICENSE$
25 **
26 ****************************************************************************/
27
28 /*!
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
33
34     \image minimal-example.png
35
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.
40
41     \include examples-run.qdocinc
42
43     \section1 C++ Code
44
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}.
48
49     \quotefromfile webengine/minimal/main.cpp
50     \skipto #include
51     \printto main
52
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.
56
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.
61
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}.
64
65     Finally, QGuiApplication::exec() launches the main event loop.
66
67     \printuntil }
68
69     \section1 QML Code
70
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}.
74
75     \quotefromfile webengine/minimal/main.qml
76     \skipto import
77     \printuntil }
78     \printline }
79
80     \section1 Requirements
81
82     The example requires a working internet connection to render the
83     \l{Qt Homepage}.
84     An optional system proxy should be picked up automatically.
85 */