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