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