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-javascript-topic.html
5
\meta {keywords} {qmltopic}
6
\title Integrating QML and JavaScript
7
\brief Description of how to use JavaScript in QML applications
8
9
The QML language uses a JSON-like syntax and allows various expressions and
10
methods to be defined as JavaScript functions. It also allows users to import
11
JavaScript files and use the functionality those imports provide.
12
13
This allows developers and designers to leverage the knowledge they have of
14
JavaScript to quickly develop both user-interfaces and application logic.
15
16
\section1 JavaScript Expressions
17
18
QML has a deep JavaScript integration, and allows \l{Signal Attributes}
19
{signal handlers} and \l{Method Attributes}{methods} to be defined in JavaScript.
20
Another core feature of QML is the ability to specify and enforce relationships
21
between object properties using \l{Property Binding}{property bindings}, which
22
are also defined using JavaScript.
23
24
See the documentation page titled
25
\l{qtqml-javascript-expressions.html}{JavaScript Expressions in QML Documents}
26
for more information about using JavaScript expressions in QML.
27
28
\section1 Dynamic QML Object Creation from JavaScript
29
30
QML supports the dynamic creation of objects from within JavaScript. This is
31
useful to delay instantiation of objects until necessary, thereby improving
32
application startup time. It also allows visual objects to be dynamically
33
created and added to the scene in reaction to user input or other events. This
34
functionality can be used in two main ways.
35
36
Object can be created dynamically from JavaScript in an imperative way using
37
\l{qtqml-javascript-dynamicobjectcreation.html}{dynamic creation of objects}.
38
This can be useful, for example, when QML is used as an application scripting
39
language.
40
41
\note When creating user interfaces, the preferred way of creating objects
42
dynamically is to use declarative constructs as these integrate best with the
43
QML engine and tooling. Various types exist to enable this functionality such
44
as the \l{Loader}, \l{Instantiator}, \l{Repeater} types.
45
46
47
\section1 JavaScript Resources
48
49
Application logic defined in JavaScript functions may be separated into
50
separate JavaScript files known as JavaScript resources. There are several
51
different kinds of JavaScript resources, with different semantics.
52
53
See the documentation page titled \l{qtqml-javascript-resources.html}
54
{Defining JavaScript Resources In QML} for more information about defining JavaScript
55
resources for QML.
56
57
\section1 JavaScript Imports
58
59
A QML document may import JavaScript resources, and JavaScript resources may
60
import other JavaScript resources as well as QML modules. This allows an
61
application developer to provide application logic in modular, self-contained
62
files.
63
64
See the documentation page titled
65
\l{qtqml-javascript-imports.html}{Importing JavaScript Resources}
66
for more information on how to import JavaScript resources and how to use the
67
functionality they provide.
68
69
\section1 JavaScript Host Environment
70
71
The QML engine provides a JavaScript environment that has some differences to
72
the JavaScript environment provided by a web browser. Certain limitations
73
apply to code running in the environment, and the QML engine provides various
74
objects in the root context which may be unfamiliar to JavaScript developers.
75
76
These limitations and extensions are documented in the description of the
77
\l{qtqml-javascript-hostenvironment.html}{JavaScript Host Environment} provided
78
by the QML engine.
79
80
There is also an in depth description of the
81
\l{qtqml-javascript-memory.html}{memory management} employed by the JavaScript
82
engine.
83
84
\section1 Configuring the JavaScript engine
85
86
For specific use cases you may want to override some of the parameters the
87
JavaScript engine uses for handling memory and compiling JavaScript. See
88
\l{qtqml-javascript-finetuning.html}{Configuring the JavaScript engine} for
89
more information on these parameters.
90
91
\section1 Making Applications Scriptable
92
93
Beyond using JavaScript within QML documents, Qt also allows you to embed a
94
JavaScript engine in C++ applications to make them scriptable. This allows
95
extending application functionality using JavaScript without recompiling the
96
application.
97
98
See \l{Making Applications Scriptable} for detailed information about using
99
the JavaScript engine in C++ applications, including how to expose QObject
100
instances to scripts and security considerations.
101
102
*/
qtdeclarative
src
qml
doc
src
javascript
topic.qdoc
Generated on
for Qt by
1.16.1