aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/src/modules/topic.qdoc
blob: dd3e4de66115b5b180a5f5f9691175e3da26fd1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** GNU Free Documentation License
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms
** and conditions contained in a signed written agreement between you
** and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\page qtqml-modules-topic.html
\title QML Modules
\brief Description of how to write modules for QML

A module is a collection of content files that can be imported as a unit into a QML
application. Modules can be used to organize QML content into independent groups,
and they use a versioning mechanism that allows modules to be independently upgraded.

Modules may contain QML files, JavaScript files and/or QML plugins written in C++. Grouping files
into modules enables:

\list
\li The sharing of common QML types within a project - for example, a group of UI components that
    are used by different windows
\li The distribution of QML-based libraries
\li The modularization of distinct features, so that applications only load the libraries necessary
    for their individual needs
\endlist

A module may contain QML, JavaScript and/or C++ files. To access the types and functionality within
a module, the module must be imported with an \l{Import Statements}{import} statement.

\section1 Located Modules

A located module is one that is imported by a quoted URL string that refers to the
local file system path of the module or the network URL location of the module.

Using this mechanism, any directory of QML files can easily be shared as a module without any
configuration or installation. Additionally, such modules can be loaded remotely as a network
resource if it includes a qmldir file with the necessary metadata.

See \l{qtqml-modules-locatedmodules.html}{Located Modules} for more information.


\section1 Installed Modules

An installed module is one that is imported by a URI in the form of a dotted identifier string - for
example, "com.mycompany.mymodule" - that uniquely identifies the module to the QML engine. This
allows a module to be imported by an identifier rather than a file system path.

To enable the engine to find an installed module, the module should be available in the
\l{qtqml-syntax-imports.html#qml-import-path}{import path}.

See \l{qtqml-modules-installedmodules.html}{Installed Modules} for more information.


\section1 Adding Module Metadata with a qmldir File

A qmldir file is a plain text file that describes a module's metadata and contents. This file and
the associated module contents (QML documents, JavaScript files, and C++ plugins) must be placed
somewhere into the \l{qtqml-syntax-imports.html#qml-import-path}{QML import path}.

This is required for a module if it is to be imported by URI or as a network resource. It is also
necessary for exporting JavaScript files and object types defined in C++.

See \l{qtqml-modules-qmldir.html}{Adding Module Metadata with a qmldir File} for more information.

\section1 Providing Types and Functionality in a C++ Plugin

An application which has a lot of logic implemented in C++, or which defines
types in C++ and exposes them to QML, may wish to implement a QML plugin.  A
QML extension module developer may wish to implement some types in a C++ plugin
(as opposed to defining them via QML documents) to achieve better performance
or for greater flexibility.

Every C++ plugin for QML has an initialiatization function which is called by
the QML engine when it loads the plugin.  This initialization function must
register any types that the plugin provides, but must not do anything else
(for example, instantiating QObjects is not allowed).

See \l{qtqml-modules-cppplugins.html}{Creating C++ Plugins For QML} for more information.

*/