1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the documentation of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:FDL$
9 ** GNU Free Documentation License
10 ** Alternatively, this file may be used under the terms of the GNU Free
11 ** Documentation License version 1.3 as published by the Free Software
12 ** Foundation and appearing in the file included in the packaging of
16 ** Alternatively, this file may be used in accordance with the terms
17 ** and conditions contained in a signed written agreement between you
26 ****************************************************************************/
28 \page qtqml-modules-qmldir.html
29 \title Adding Module Metadata with a qmldir File
30 \brief How to write a qmldir file for a module
32 A \e qmldir file is a metadata file for a module that maps all type names in the module to
33 versioned QML files. It is required for \l{qtqml-modules-installedmodules.html}{installed modules},
34 as well as \l{qtqml-modules-locatedmodules.html}{located modules} that are loaded from a network
37 This file is defined by a plain text file named "qmldir" within the module. For
38 \l{qtqml-modules-locatedmodules.html}{located modules}, this file should be in the module's root
39 directory. For \l{qtqml-modules-installedmodules.html}{installed modules}, the file should be in a
40 directory within the module according to the named identifier for the module; see the \l{Installed
41 Modules} documentation for more information.
44 \section1 Writing a qmldir File
46 A \c qmldir file contains one or more lines of the following commands:
56 <TypeName> [<InitialVersion>] <File>
58 \li Declares an \l{qtqml-typesystem-objecttypes.html}{object type} to be made available by
61 \li \c <TypeName> is the type being made available
62 \li \c <InitialVersion> (optional) is the module version for which the type is to be
64 \li \c <File> is the (relative) file name of the QML file that defines the type
69 MyCustomType 1.0 MyCustomType.qml
74 internal <TypeName> <File>
76 \li Declares an object type that is in the module but should not be made available to users
81 internal MyPrivateType MyPrivateType.qml
84 This is necessary if the module may be imported remotely (see \l{Remotely Located
85 Modules} and \l{Remotely Installed Modules}) because if an exported type depends on an
86 non-exported type within the module, the engine must also load the non-exported type.
91 <Namespace> <InitialVersion> <File>
93 \li Declares a JavaScript file to be made available by the module. The file will be made
94 available through the specified namespace and verison number.
98 MyScript 1.0 MyScript.js
101 See \l{qtqml-javascript-imports.html}{Importing JavaScript Files in QML Documents} for
107 plugin <Name> [<Path>]
109 \li Declares a plugin to be made available by the module.
112 \li \c <Name> is the plugin library name. This is usually not the same as the file name
113 of the plugin binary, which is platform dependent; e.g. the library \c MyAppTypes
114 would produce \c libMyAppTypes.so on Linux and \c MyAppTypes.dll on Windows.
115 \li \c <Path> (optional) specifes either:
117 \li an absolute path to the directory containing the plugin file, or
118 \li a relative path from the directory containing the \c qmldir file to the
119 directory containing the plugin file.
122 By default the engine searches for the plugin library in the directory that contains
123 the \c qmldir file. (The plugin search path can be queried with
124 QQmlEngine::pluginPathList() and modified using QQmlEngine::addPluginPath().)
129 plugin MyPluginLibrary
137 \li Declares a \l{Writing a qmltypes file}{type description file} for the module that can be
138 read by QML tools such as Qt Creator to access information about the types defined by the module's plugins. \c <File> is the (relative) file name of a \c .qmltypes file.
142 typeinfo mymodule.qmltypes
145 Without such a file, QML tools may be unable to offer features such as code completion
146 for the types defined in your plugins.
153 \li Declares a comment. These are ignored by the engine.
161 For example, suppose a module's \c qmldir file should export a \c MyButton type in version 1.0, a \c
162 MyWindow type in version 1.1 and a JavaScript file to a \c MyScript namespace in version 1.1.
163 Providing the relevant files are in the same directory as the \c qmldir file, the contents of the \c
164 qmldir file would look like this:
167 MyButton 1.0 MyButton.qml
168 MyWindow 1.1 MyWindow.qml
169 MyScript 1.1 myscript.js
172 If these files were part of an \l{qtqml-modules-installedmodules.html}{installed module} named \c
173 com.mycompany.module then the module could be imported and its exported types used as follows:
176 import com.mycompany.module 1.1
180 MyScript.doSomething();
189 Types which are exported for a particular version are still made available if a later version is
190 imported: in the above example, the code imports version 1.1 of the module but still has access to
191 the \c MyButton type that was exported for version 1.0. However, the reverse is not true: a type
192 exported for a particular version cannot be used if an earlier version is imported. If the code
193 above imported version 1.0 of the module, it could not have used the \c MyWindow type and \c
194 MyScript namespace as these are declared for version 1.1.
196 A type can be defined by different files in different versions. In this case, later versions (e.g.
197 1.2) must precede earlier versions (e.g. 1.0) within the \c qmldir file, since the engine loads the
198 first type it finds with a matching name and version.
200 The versioning system ensures that a given QML file will work regardless of the version
201 of installed software, since a versioned import \e only imports types for that version,
202 leaving other identifiers available, even if the actual installed version might otherwise
203 provide those identifiers.
205 See \l{Located Modules} and \l{Installed Modules} for more example \c qmldir file content, and see
206 \l{examples/qml/cppextensions/plugins} for an example that uses C++ plugins.
209 \section1 Writing a qmltypes File
211 QML modules may refer to one or more type information files in their
212 \c qmldir file. These usually have the \c .qmltypes
213 extension and are read by external tools to gain information about
214 types defined in plugins.
216 As such qmltypes files have no effect on the functionality of a QML module.
217 Their only use is to allow tools such as Qt Creator to provide code completion,
218 error checking and other functionality to users of your module.
220 Any module that uses plugins should also ship a type description file.
222 The best way to create a qmltypes file for your module is to generate it
223 using the \c qmlplugindump tool that is provided with Qt.
226 If your module is in \c /tmp/imports/My/Module, you could run
228 qmlplugindump My.Module 1.0 /tmp/imports > /tmp/imports/My/Module/mymodule.qmltypes
230 to generate type information for your module. Afterwards, add the line
232 typeinfo mymodule.qmltypes
234 to \c /tmp/imports/My/Module/qmldir to register it.
236 While the qmldump tool covers most cases, it does not work if:
238 \li The plugin uses a \l{QQmlCustomParser}. The component that uses
239 the custom parser will not get its members documented.
240 \li The plugin can not be loaded. In particular if you cross-compiled
241 the plugin for a different architecture, qmldump will not be able to
245 In case you have to create a qmltypes file manually or need to adjust
246 an existing one, this is the file format:
249 import QtQuick.tooling 1.1
251 // There always is a single Module object that contains all
252 // Component objects.
254 // A Component object directly corresponds to a type exported
255 // in a plugin with a call to qmlRegisterType.
258 // The name is a unique identifier used to refer to this type.
259 // It is recommended you simply use the C++ type name.
260 name: "QQuickAbstractAnimation"
262 // The name of the prototype Component.
265 // The name of the default property.
266 defaultProperty: "animations"
268 // The name of the type containing attached properties
270 attachedType: "QDeclarativeAnimationAttached"
272 // The list of exports determines how a type can be imported.
273 // Each string has the format "URI/Name version" and matches the
274 // arguments to qmlRegisterType. Usually types are only exported
276 // If the "URI/" part of the string is missing that means the
277 // type should be put into the package defined by the URI the
278 // module was imported with.
279 // For example if this module was imported with 'import Foo 4.8'
280 // the Animation object would be found in the package Foo and
284 "QtQuick/Animation 1.0"
287 // The meta object revisions for the exports specified in 'exports'.
288 // Describes with revisioned properties will be visible in an export.
289 // The list must have exactly the same length as the 'exports' list.
290 // For example the 'animations' propery described below will only be
291 // available through the QtQuick/Animation 1.0 export.
292 exportMetaObjectRevisions: [0, 1]
296 type: "QQuickAbstractAnimation"
297 // defaults to false, whether this property is read only
299 // defaults to false, whether the type of this property was a pointer in C++
301 // defaults to false: whether the type actually is a QQmlListProperty<type>
303 // defaults to 0: the meta object revision that introduced this property
306 Property { name: "loops"; type: "int" }
307 Property { name: "name"; type: "string" }
308 Property { name: "loopsEnum"; type: "Loops" }
318 // Signal and Method work the same way. The inner Parameter
319 // declarations also support the isReadonly, isPointer and isList
320 // attributes which mean the same as for Property
321 Method { name: "restart" }
322 Signal { name: "started"; revision: 2 }
324 name: "runningChanged"
325 Parameter { type: "bool" }
326 Parameter { name: "foo"; type: "bool" }