2011-12-14 15:07:05 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:51:16 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-12-14 15:07:05 +01:00
|
|
|
**
|
2016-01-15 14:51:16 +01:00
|
|
|
** This file is part of the Qt Creator documentation.
|
2011-12-14 15:07:05 +01:00
|
|
|
**
|
2016-01-15 14:51:16 +01:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-12-14 15:07:05 +01:00
|
|
|
**
|
2016-01-15 14:51:16 +01:00
|
|
|
** GNU Free Documentation License Usage
|
2011-12-14 15:07:05 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Free
|
|
|
|
|
** Documentation License version 1.3 as published by the Free Software
|
2016-01-15 14:51:16 +01:00
|
|
|
** Foundation and appearing in the file included in the packaging of
|
|
|
|
|
** this file. Please review the following information to ensure
|
|
|
|
|
** the GNU Free Documentation License version 1.3 requirements
|
|
|
|
|
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
|
2011-12-14 15:07:05 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
// NOTE: the sections are not ordered by their logical order to avoid
|
|
|
|
|
// reshuffling the file each time the index order changes (i.e., often).
|
|
|
|
|
// Run the fixnavi.pl script to adjust the links to the index order.
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
|
|
/*!
|
2014-03-17 12:18:12 +01:00
|
|
|
\contentspage {Qt Creator Manual}
|
2013-10-07 13:45:08 +02:00
|
|
|
\previouspage quick-export-to-qml.html
|
2011-12-14 15:07:05 +01:00
|
|
|
\page creator-qml-modules-with-plugins.html
|
|
|
|
|
\nextpage creator-using-qt-designer.html
|
|
|
|
|
|
|
|
|
|
\title Using QML Modules with Plugins
|
|
|
|
|
|
|
|
|
|
QML modules may use plugins to expose components defined in C++ to QML
|
|
|
|
|
applications. \QC cannot load the plugins to determine the details of
|
|
|
|
|
the contained components, and therefore, the modules must provide extra type
|
|
|
|
|
information for code completion and the semantic checks to work correctly.
|
|
|
|
|
|
|
|
|
|
When you write a QML module or use QML from a C++ application you typically
|
2016-10-18 17:08:46 +02:00
|
|
|
register new types with the qmlRegisterType() function or expose some
|
2013-11-25 17:37:19 +01:00
|
|
|
class instances with \l{QQmlContext::setContextProperty()}. The \QC C++
|
|
|
|
|
code model now scans for these calls and
|
2011-12-14 15:07:05 +01:00
|
|
|
tells the QML code model about them. This means that properties are
|
|
|
|
|
displayed during code completion and the JavaScript code checker does not
|
|
|
|
|
complain about unknown types. However, this works only when the source code
|
|
|
|
|
is available, and therefore, you must explicitly generate type information
|
|
|
|
|
for QML modules with plugins before distributing them.
|
|
|
|
|
|
2016-10-18 16:35:50 +02:00
|
|
|
Classes registered with \c qmlRegisterType() can be used as backend objects
|
|
|
|
|
in the \QMLD. For more information, see \l {Adding Connections}.
|
|
|
|
|
|
2016-10-25 09:51:39 +02:00
|
|
|
By default, \QC will look in the QML import path of Qt for QML modules.
|
|
|
|
|
If your applications adds additional import paths that \QC should use,
|
|
|
|
|
then you can specify those using \c{QML_IMPORT_PATH} in the \c{.pro} file of your
|
|
|
|
|
application.
|
|
|
|
|
|
2017-01-31 13:10:53 +01:00
|
|
|
If you use CMake, add the following command to the CMakeLists.txt file to
|
|
|
|
|
set the QML import path:
|
|
|
|
|
|
|
|
|
|
\code
|
|
|
|
|
{set(QML_IMPORT_PATH ${CMAKE_SOURCE_DIR}/qml ${CMAKE_BINARY_DIR}/imports CACHE string "" FORCE)}
|
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
|
|
The import path affects all the targets built by the CMake project.
|
|
|
|
|
|
2011-12-14 15:07:05 +01:00
|
|
|
Ideally, QML modules have a \c{plugins.qmltypes} file in the same directory
|
|
|
|
|
as the \c qmldir file. The \c qmltypes file contains a description of the
|
2013-03-13 11:39:36 +01:00
|
|
|
types exported by the module's plugins and is loaded by \QC when the
|
2011-12-14 15:07:05 +01:00
|
|
|
module is imported.
|
|
|
|
|
|
|
|
|
|
For Qt 4.8 and later, one or more \c qmltypes files can be listed in the
|
|
|
|
|
\c qmldir file under the \c typeinfo header. These files will be read in
|
|
|
|
|
addition to \c{plugins.qmltypes}. For more information, see
|
2013-11-25 17:37:19 +01:00
|
|
|
\l{Writing a qmltypes File}.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
\section1 Generating qmltypes Files
|
|
|
|
|
|
|
|
|
|
You can create and edit \c qmltypes files manually, but you are recommended
|
|
|
|
|
to use the \c qmlplugindump tool shipped with Qt 4.8 and later to generate
|
2012-05-10 16:00:17 +02:00
|
|
|
them automatically.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
Once you have obtained qmlplugindump for the Qt version the QML module's
|
|
|
|
|
plugins were compiled with, run the following command to load My.Module
|
|
|
|
|
version 1.0 from \c{/import/path/my/module} including all its plugins and
|
|
|
|
|
output a description of the plugins' types to
|
|
|
|
|
\c{/import/path/my/module/plugins.qmltypes}:
|
|
|
|
|
|
|
|
|
|
\code
|
|
|
|
|
qmlplugindump My.Module 1.0 /import/path > /import/path/my/module/plugins.qmltypes
|
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
|
|
You can safely ignore the debug output.
|
|
|
|
|
|
2012-05-10 16:00:17 +02:00
|
|
|
For Qt 4.7.x, you can compile a version of the tool called \c qmldump from
|
|
|
|
|
the sources in \c{<QtCreator>/share/qtcreator/qml/qmldump} if the Qt version
|
|
|
|
|
contains private headers.
|
|
|
|
|
|
2011-12-14 15:07:05 +01:00
|
|
|
\section1 Dumping Plugins Automatically
|
|
|
|
|
|
|
|
|
|
If a module with plugins lacks the \c qmltypes file, \QC tries to generate
|
|
|
|
|
a temporary file itself by running the \c qmldump program in the background.
|
|
|
|
|
However, this automatic dumping is a fallback mechanism with many points of
|
|
|
|
|
failure and you cannot rely upon it.
|
|
|
|
|
|
2014-09-11 15:30:11 +02:00
|
|
|
\section1 Running QML Modules in Qt Quick Designer
|
|
|
|
|
|
|
|
|
|
\QMLD uses a QML emulation layer (also called QML Puppet) to render and
|
|
|
|
|
preview images and to collect data. To be able to render custom types
|
|
|
|
|
correctly from QML modules, the emulation layer must be built with the same
|
|
|
|
|
Qt version as the QML modules.
|
|
|
|
|
|
2014-11-27 17:37:14 +01:00
|
|
|
By default, a fallback emulation layer is provided by \QC and built with the same
|
2014-09-11 15:30:11 +02:00
|
|
|
Qt version as \QC. Therefore, your QML modules will mostly not work out of
|
|
|
|
|
the box.
|
|
|
|
|
|
|
|
|
|
To use an emulation layer that is built with the Qt
|
2014-12-11 15:43:19 +01:00
|
|
|
configured in the build and run kit for the project, select \uicontrol Tools >
|
|
|
|
|
\uicontrol Options > \uicontrol {Qt Quick} > \uicontrol {Qt Quick Designer} >
|
|
|
|
|
\uicontrol {Use QML emulation layer which is built by the selected Qt} radio button.
|
|
|
|
|
\QC builds the emulation layer when you select the \uicontrol Design mode.
|
2014-09-11 15:30:11 +02:00
|
|
|
|
2014-11-28 15:28:15 +01:00
|
|
|
A plugin should behave differently depending on whether it is run by the
|
|
|
|
|
emulation layer or an application. For example, animations should not be run
|
2014-12-11 15:43:19 +01:00
|
|
|
in the \uicontrol Design mode. You can use the value of the QML_PUPPET_MODE
|
2014-11-28 15:28:15 +01:00
|
|
|
environment variable to check whether the plugin is currently being run
|
2014-12-11 15:43:19 +01:00
|
|
|
by an application or edited in the \uicontrol Design mode.
|
2014-11-28 15:28:15 +01:00
|
|
|
|
2016-10-25 09:51:39 +02:00
|
|
|
If you want to use a different module in \QMLD than in your actual
|
|
|
|
|
application for example to mockup C++ items, then you can use \c{QML_DESIGNER_IMPORT_PATH}
|
|
|
|
|
in the \c{.pro} file.
|
|
|
|
|
Modules in the import paths defined in \c{QML_DESIGNER_IMPORT_PATH} will be used only in \QMLD.
|
2017-05-08 16:29:01 +02:00
|
|
|
For an example, see \l {Qt Quick Controls 2 - Contact List}.
|
2016-10-25 09:51:39 +02:00
|
|
|
|
2011-12-14 15:07:05 +01:00
|
|
|
*/
|