Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
8The \l{Qt Qml} module provides C++ classes which implement the QML framework.
9Clients can use these classes to interact with the QML run-time (for example,
10by injecting data or invoking methods on objects), and to instantiate a
11hierarchy of objects from a QML document. The Qt QML module provides more
12C++ API than just the classes listed here, however the classes listed here
13provide the foundations of the QML runtime and the core concepts of QML.
14
15\section1 QML Runtime
16
17A typical QML application with a C++ entry-point will instantiate a QQmlEngine
18and then use a QQmlComponent to load a QML document. The engine provides a
19default QQmlContext which will be the top-level evaluation context used for
20evaluating functions and expressions defined in the QML document.
21The object hierarchy defined in the QML document will be instantiated by
22calling the \l{QQmlComponent::create()}{create()} function of the QQmlComponent
23instance, assuming that no errors were encountered during document loading.
24
25The client may wish to modify the QQmlContext provided by the engine, by
26injecting properties or objects into the context. They can call the
27\l{QQmlEngine::rootContext()} function to access the top-level context.
28
29After instantiating the object, the client will usually pass control to the
30application event loop so that user input events (like mouse-clicks) can be
31delivered and handled by the application.
32
33\note The Qt Quick module provides a convenience class, QQuickView, which
34provides a QML runtime and visual window for displaying a QML application.
35
36\section2 The QQmlEngine Class
37
38The QQmlEngine class provides an engine which can manage a hierarchy of objects
39which is defined in a QML document. It provides a root QML context within
40which expressions are evaluated, and ensures that properties of objects are
41updated correctly when required.
42
43A QQmlEngine allows the configuration of global settings that apply to all of
44the objects it manages; for example, the QNetworkAccessManager to be used for
45network communications, and the file path to be used for persistent storage.
46
47See the \l{QQmlEngine} class documentation for in-depth information about what
48the QQmlEngine class provides, and how it can be used in an application.
49
50\section2 The QQmlContext Class
51
52The QQmlContext class provides a context for object instantiation and
53expression evaluation. All objects are instantiated in a particular context,
54and all of the expressions which are evaluated while an application is running
55are evaluated within a particular context. This context defines how symbols
56are resolved, and thus which values the expression operates on.
57
58See the \l{QQmlContext} class documentation for in-depth information about
59how to modify the evaluation context of an object by adding or removing
60properties of a QQmlContext, and how to access the context for an object.
61
62\section1 Dynamic Object Instantiation and Expression Evaluation
63
64Dynamic object instantiation and dynamic expression evaluation are both core
65concepts in QML. QML documents define object types which can be instantiated
66at run-time using a QQmlComponent. An instance of the QQmlComponent class can
67be created in C++ directly, or via the \l{QtQml::Qt::createComponent()}
68{Qt.createComponent()} function in imperative QML code. Arbitrary expressions
69can be calculated in C++ via the QQmlExpression class, and such expressions
70can interact directly with the QML context.
71
72\section2 The QQmlComponent Class
73
74The QQmlComponent class can be used to load a QML document. It requires a
75QQmlEngine in order to instantiate the hierarchy of objects defined in the QML
76document.
77
78See the \l{QQmlComponent} class documentation for in-depth information about
79how to use QQmlComponent.
80
81\section2 The QQmlExpression Class
82
83The QQmlExpression class provides a way for clients to evaluate JavaScript
84expressions from C++, using a particular QML evaluation context. This allows
85clients to access QML objects by id, for example. The result of the evaluation
86is returned as a QVariant, and the conversion rules are defined by the QML
87engine.
88
89See the \l{QQmlExpression} class documentation for in depth information about
90how to use QQmlExpression in an application.
91
92\section1 Usage of the Classes within QML Applications
93
94These pages describe how to create QML applications which interact with the
95C++ 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*/