summaryrefslogtreecommitdiffstats
path: root/examples/applicationmanager/application-features/doc/src/application-features.qdoc
blob: a2ccb99b8e616074bc027f9453c8ece04c586525 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!

\example applicationmanager/application-features
\title Application Features Example
\image application-features.png
\brief Showcases client applications with various features, including a native application.
\ingroup applicationmanager-examples

\section1 Introduction

This example demonstrates how to implement some particular features you may require in an
application, such as:

\list
    \li how to implement a nested compositor
    \li how to simulate a crash and recover from it
    \li how to show multiple top-level windows simultaneously
    \li how to use the native runtime, with no QML

\endlist

Most of these features are only supported properly in
\l{Single-Process vs. Multi-Process Mode}{multi-process mode}.

\note This example focuses on the application (client) side. The \l{The System UI}{System UI}
(compositor/server) is based on the \l{Desktop System UI Example} with some modifications. Refer
to that example for more details on how to implement a System UI.

\section2 Nested Compositor

The nested compositor application shows how to implement a Wayland compositor inside an application
(Wayland client) window. The compositor is implemented in pure QML and kept to a minimum. To
display Wayland clients within this compositor, you need to set the \c WAYLAND_DISPLAY environment
variable appropriately.

To start a client with this environment variable set via command line:

\badcode
WAYLAND_DISPLAY=qtam-wayland-nested qml client.qml -platform wayland
\endcode

This command only works in multi-process mode, since the nested compositor needs a real window as
its root element.

The QML code for the nested compositor application is as follows:

\quotefromfile applicationmanager/application-features/apps/compositor/compositor.qml
\skipto import QtQuick 2.11
\printuntil /^\}/

\section2 Crash Simulation and Recovery

This application provides various means to force a crash in an application, such as a segmentation
fault. It utilizes a QML plugin implemented in C++, to provide the \c Terminator QML type to
trigger crashes. The application manager then prints the cause of the crash and related
information, like a backtrace. The System UI implements a basic form of crash recovery: restarting
the application.

This application only works on multi-process mode. In single-process mode a crash affects the entire
program (the System UI).

The QML code for the crash simulation and recovery application is as follows:

\quotefromfile applicationmanager/application-features/apps/crash/crashapp.qml
\skipto import QtQuick 2.11
\printuntil case "gracefully": Terminator.exitGracefully(); break;
\printuntil /^\}/

\section2 Two Top-Level Windows

This application illustrates how you can display multiple top-level windows by having a QtObject
as the application's root element.

The QML code for the two top-level windows application is as follows:

\quotefromfile applicationmanager/application-features/apps/twins/twins.qml
\skipto import QtQuick 2.11
\printuntil Component.onCompleted: setWindowProperty("type", "pop-up");
\printuntil /^\}/

\section2 Native Widgets

This application is based on \l{QWidget}s. Compared to the other applications in this example,
which are QML applications, this one uses the native runtime. Consequently, the application's entry
point isn't a \c{main.qml} file, but an executable. This application is a basic application that
still adheres to this particular System UI. It's meant to illustrate the concept: the System UI
needs a \c type window property to differentiate between normal windows and popups.

This application only works in multi-process mode, as application processes cannot be started in
single-process mode.

The C++ code for the native widgets application is as follows:

\quotefromfile applicationmanager/application-features/native/widgets/main.cpp
\skipto #include <QApplication>
\printuntil /^\}/

\section1 Code Structure

Compared to the other Qt Application Manager Examples, which are purely based on QML, this example
requires you to build it explicitly. The code is structured in a way where the resulting application
folders only contain the artifacts necessary to run the application. Consequently, you can package
these applications and install them as well.

To build Qt Application Manager including its examples, you need to pass \c qmake the
\c{-config enable-examples} parameter For more details, see \l{build}{Build}.
*/