Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
topic.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
/*!
4
\page qtqml-cppclasses-topic.html
5
\title Important C++ Classes Provided By The Qt Qml Module
6
\brief Overview of the C++ classes provided by the Qt Qml module.
7
8
The \l{Qt Qml} module provides C++ classes which implement the QML framework.
9
Clients can use these classes to interact with the QML run-time (for example,
10
by injecting data or invoking methods on objects), and to instantiate a
11
hierarchy of objects from a QML document. The Qt Qml module provides more
12
C++ API than just the classes listed here, however the classes listed here
13
provide the foundations of the QML runtime and the core concepts of QML.
14
15
\section1 QML Runtime
16
17
A typical QML application with a C++ entry-point will instantiate a QQmlEngine
18
and then use a QQmlComponent to load a QML document. The engine provides a
19
default QQmlContext which will be the top-level evaluation context used for
20
evaluating functions and expressions defined in the QML document.
21
The object hierarchy defined in the QML document will be instantiated by
22
calling the \l{QQmlComponent::create()}{create()} function of the QQmlComponent
23
instance, assuming that no errors were encountered during document loading.
24
25
The client may wish to modify the QQmlContext provided by the engine, by
26
injecting properties or objects into the context. They can call the
27
\l{QQmlEngine::rootContext()} function to access the top-level context.
28
29
After instantiating the object, the client will usually pass control to the
30
application event loop so that user input events (like mouse-clicks) can be
31
delivered and handled by the application.
32
33
\note The Qt Quick module provides a convenience class, QQuickView, which
34
provides a QML runtime and visual window for displaying a QML application.
35
36
\section2 The QQmlEngine Class
37
38
The QQmlEngine class provides an engine which can manage a hierarchy of objects
39
which is defined in a QML document. It provides a root QML context within
40
which expressions are evaluated, and ensures that properties of objects are
41
updated correctly when required.
42
43
A QQmlEngine allows the configuration of global settings that apply to all of
44
the objects it manages; for example, the QNetworkAccessManager to be used for
45
network communications, and the file path to be used for persistent storage.
46
47
See the \l{QQmlEngine} class documentation for in-depth information about what
48
the QQmlEngine class provides, and how it can be used in an application.
49
50
\section2 The QQmlContext Class
51
52
The QQmlContext class provides a context for object instantiation and
53
expression evaluation. All objects are instantiated in a particular context,
54
and all of the expressions which are evaluated while an application is running
55
are evaluated within a particular context. This context defines how symbols
56
are resolved, and thus which values the expression operates on.
57
58
See the \l{QQmlContext} class documentation for in-depth information about
59
how to modify the evaluation context of an object by adding or removing
60
properties of a QQmlContext, and how to access the context for an object.
61
62
\section1 Dynamic Object Instantiation and Expression Evaluation
63
64
Dynamic object instantiation and dynamic expression evaluation are both core
65
concepts in QML. QML documents define object types which can be instantiated
66
at run-time using a QQmlComponent. An instance of the QQmlComponent class can
67
be created in C++ directly, or via the \l{QtQml::Qt::createComponent()}
68
{Qt.createComponent()} function in imperative QML code. Arbitrary expressions
69
can be calculated in C++ via the QQmlExpression class, and such expressions
70
can interact directly with the QML context.
71
72
\section2 The QQmlComponent Class
73
74
The QQmlComponent class can be used to load a QML document. It requires a
75
QQmlEngine in order to instantiate the hierarchy of objects defined in the QML
76
document.
77
78
See the \l{QQmlComponent} class documentation for in-depth information about
79
how to use QQmlComponent.
80
81
\section2 The QQmlExpression Class
82
83
The QQmlExpression class provides a way for clients to evaluate JavaScript
84
expressions from C++, using a particular QML evaluation context. This allows
85
clients to access QML objects by id, for example. The result of the evaluation
86
is returned as a QVariant, and the conversion rules are defined by the QML
87
engine.
88
89
See the \l{QQmlExpression} class documentation for in depth information about
90
how to use QQmlExpression in an application.
91
92
\section1 Usage of the Classes within QML Applications
93
94
These pages describe how to create QML applications which interact with the
95
C++ classes:
96
97
\list
98
\li \l{Overview - QML and C++ Integration}
99
\list
100
\li \l{qtqml-cppintegration-exposecppattributes.html}{Exposing Attributes of C++ Classes to QML}
101
\li \l{qtqml-cppintegration-definetypes.html}{Defining QML Types from C++}
102
\li \l{qtqml-cppintegration-contextproperties.html}{Embedding C++ Objects into QML with Context Properties}
103
\li \l{qtqml-cppintegration-interactqmlfromcpp.html}{Interacting with QML Objects from C++}
104
\li \l{qtqml-cppintegration-data.html}{Data Type Conversion Between QML and C++}
105
\endlist
106
\endlist
107
108
*/
qtdeclarative
src
qml
doc
src
cppclasses
topic.qdoc
Generated on
for Qt by
1.14.0