2011-12-14 15:07:05 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2022-02-28 10:51:05 +01:00
|
|
|
** Copyright (C) 2022 The Qt Company Ltd.
|
2016-01-15 14:51:16 +01:00
|
|
|
** 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.
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\page creator-qml-modules-with-plugins.html
|
2020-11-24 13:45:43 +01:00
|
|
|
\if defined(qtdesignstudio)
|
|
|
|
|
\previouspage studio-simulink.html
|
2021-10-05 15:50:41 +02:00
|
|
|
\nextpage qtquick-adding-dynamics.html
|
2020-11-24 13:45:43 +01:00
|
|
|
\else
|
2021-10-05 15:50:41 +02:00
|
|
|
\previouspage creator-quick-ui-forms.html
|
|
|
|
|
\nextpage creator-using-qt-designer.html
|
2020-11-24 13:45:43 +01:00
|
|
|
\endif
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
\title Using QML Modules with Plugins
|
|
|
|
|
|
2022-05-02 15:56:18 +02:00
|
|
|
\l{Defining a QML Module}{QML modules} may use \l{Creating C++ Plugins for QML}
|
|
|
|
|
{C++ plugins} to expose components defined in C++ to QML applications.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2022-05-02 15:56:18 +02:00
|
|
|
To create a QML
|
2021-10-05 15:50:41 +02:00
|
|
|
\if defined(qtdesignstudio)
|
2022-05-02 15:56:18 +02:00
|
|
|
module and make it appear in the \l Components view:
|
2021-10-05 15:50:41 +02:00
|
|
|
\else
|
2022-05-02 15:56:18 +02:00
|
|
|
module:
|
2021-10-05 15:50:41 +02:00
|
|
|
\endif
|
2017-10-17 16:56:04 +02:00
|
|
|
|
|
|
|
|
\list 1
|
|
|
|
|
|
2021-03-16 15:27:48 +01:00
|
|
|
\li Create custom components and place all the \c .qml files in a
|
2020-11-24 13:45:43 +01:00
|
|
|
directory dedicated to your module. For example:
|
|
|
|
|
\c {imports\asset_imports}.
|
2017-10-17 16:56:04 +02:00
|
|
|
|
2020-11-24 13:45:43 +01:00
|
|
|
\li For Qt Quick UI projects (.qmlproject), specify the path to
|
|
|
|
|
the directory that contains the module in the .qmlproject file
|
|
|
|
|
of the application where you want to use the module
|
|
|
|
|
as a value of the \c importPaths variable. For example
|
|
|
|
|
\c{importPaths: [ "imports", "asset_imports" ]}.
|
|
|
|
|
|
|
|
|
|
\li Create a \c qmldir file for your module and place it
|
|
|
|
|
in the module directory. For more information, see
|
2017-10-17 16:56:04 +02:00
|
|
|
\l {Module Definition qmldir Files}.
|
|
|
|
|
|
2022-02-18 16:48:33 +01:00
|
|
|
\li Create a \c qmltypes file, as instructed in
|
|
|
|
|
\l {Generating Type Description Files}.
|
2017-10-17 16:56:04 +02:00
|
|
|
|
|
|
|
|
\li Create a directory named \c designer in your module directory.
|
|
|
|
|
|
|
|
|
|
\li Create a \c .metainfo file for your module and place it in the
|
2021-10-05 15:50:41 +02:00
|
|
|
\c designer directory.
|
|
|
|
|
\if defined(qtdesignstudio)
|
2022-02-28 10:51:05 +01:00
|
|
|
Meta information is needed to display the components in
|
|
|
|
|
\uicontrol Components.
|
2021-10-05 15:50:41 +02:00
|
|
|
\endif
|
2021-03-16 15:27:48 +01:00
|
|
|
Use a metainfo file delivered with Qt, such as
|
2017-10-17 16:56:04 +02:00
|
|
|
\c qtquickcontrols2.metainfo, as an example.
|
|
|
|
|
|
2020-11-24 13:45:43 +01:00
|
|
|
\if defined(qtcreator)
|
|
|
|
|
\li Import the module into the project, as instructed in
|
|
|
|
|
\l {Importing QML Modules}.
|
2021-10-05 15:50:41 +02:00
|
|
|
\endlist
|
2020-11-24 13:45:43 +01:00
|
|
|
\else
|
|
|
|
|
\li Build your module using the same Qt version and compiler as \QDS.
|
|
|
|
|
For more information, see \l {Running QML Modules in Design Mode}.
|
2021-10-05 15:50:41 +02:00
|
|
|
\endlist
|
2017-10-17 16:56:04 +02:00
|
|
|
|
2022-02-28 10:51:05 +01:00
|
|
|
Your module should now appear in \uicontrol Components. Your components
|
|
|
|
|
should appear in a subsection of \uicontrol Components if a valid
|
|
|
|
|
\c .metainfo file is in place.
|
2021-10-05 15:50:41 +02:00
|
|
|
\endif
|
2017-10-17 16:56:04 +02:00
|
|
|
|
2022-02-18 16:48:33 +01:00
|
|
|
\section1 Generating Type Description Files
|
2017-01-31 13:10:53 +01:00
|
|
|
|
2022-05-02 15:56:18 +02:00
|
|
|
When \l{Defining QML Types from C++}{registering QML types}, make sure that
|
|
|
|
|
the QML module has a \c{plugins.qmltypes} file. Ideally, it should be located
|
|
|
|
|
in the same directory as the \c qmldir file. The \c qmltypes file contains a
|
|
|
|
|
description of the components exported by the module's plugins and is loaded
|
|
|
|
|
by \QC when the module is imported.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2022-02-18 16:48:33 +01:00
|
|
|
For more information, see \l{Type Description Files}.
|
2012-05-10 16:00:17 +02:00
|
|
|
|
2017-10-17 16:56:04 +02:00
|
|
|
\section2 Dumping Plugins Automatically
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
2017-10-17 16:56:04 +02:00
|
|
|
\section1 Importing QML Modules
|
|
|
|
|
|
|
|
|
|
By default, \QC will look in the QML import path of Qt for QML modules.
|
2020-11-24 13:45:43 +01:00
|
|
|
|
|
|
|
|
If you use qmake and your application adds additional import paths that
|
|
|
|
|
\QC should use, specify them using \c{QML_IMPORT_PATH} in the \c{.pro}
|
|
|
|
|
file of your application: \c {QML_IMPORT_PATH += path/to/module}.
|
2017-10-17 16:56:04 +02:00
|
|
|
|
|
|
|
|
If you use CMake, add the following command to the CMakeLists.txt file to
|
|
|
|
|
set the QML import path:
|
|
|
|
|
|
|
|
|
|
\code
|
2019-09-08 16:37:08 +03:00
|
|
|
set(QML_IMPORT_PATH ${CMAKE_SOURCE_DIR}/qml ${CMAKE_BINARY_DIR}/imports CACHE STRING "" FORCE)
|
2017-10-17 16:56:04 +02:00
|
|
|
\endcode
|
|
|
|
|
|
|
|
|
|
The import path affects all the targets built by the CMake project.
|
|
|
|
|
|
2022-05-02 15:56:18 +02:00
|
|
|
\if defined(qtdesignstudio)
|
2018-06-25 17:46:23 +02:00
|
|
|
\section1 Running QML Modules in Design Mode
|
2014-09-11 15:30:11 +02:00
|
|
|
|
2021-10-05 15:50:41 +02:00
|
|
|
A QML emulation layer (also called QML Puppet) is used in the
|
|
|
|
|
\uicontrol Design mode to render and preview images and to collect
|
|
|
|
|
data. To be able to render custom components correctly from QML modules,
|
|
|
|
|
the emulation layer must be built with the same Qt version and compiler
|
|
|
|
|
as the QML modules.
|
2014-09-11 15:30:11 +02:00
|
|
|
|
2020-11-24 13:45:43 +01:00
|
|
|
On Windows, select \uicontrol Help > \uicontrol {About Qt Design Studio} to
|
|
|
|
|
check the Qt version and compiler that you need to use to build your plugin.
|
|
|
|
|
For example: \c {Based on Qt 5.15.2 (MSVC 2019, 64 bit)}.
|
|
|
|
|
|
|
|
|
|
On macOS, select \uicontrol {Qt Design Studio} >
|
|
|
|
|
\uicontrol {About Qt Design Studio} to see something like:
|
|
|
|
|
\c {Based on Qt 5.15.2 (Clang 10.0 (Apple), 64 bit)}.
|
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
|
2021-10-05 15:50:41 +02:00
|
|
|
in the \uicontrol Design mode. You can use the value of the \c QML_PUPPET_MODE
|
2014-11-28 15:28:15 +01:00
|
|
|
environment variable to check whether the plugin is currently being run
|
2021-10-05 15:50:41 +02:00
|
|
|
by an application or edited in the \uicontrol Design mode.
|
2014-11-28 15:28:15 +01:00
|
|
|
|
2021-10-05 15:50:41 +02:00
|
|
|
If you want to use a different module in the \uicontrol Design mode
|
2022-05-02 15:56:18 +02:00
|
|
|
than in your actual application for example to mockup C++ items,
|
2021-10-05 15:50:41 +02:00
|
|
|
you can use \c{QML_DESIGNER_IMPORT_PATH}
|
2018-08-20 14:48:02 +02:00
|
|
|
in the \c{.pro} file (for qmake projects), or declare and set the property
|
2020-11-24 13:45:43 +01:00
|
|
|
\c qmlDesignerImportPaths in your product (for Qbs projects).
|
2018-06-25 17:46:23 +02:00
|
|
|
Modules in the import paths defined in \c{QML_DESIGNER_IMPORT_PATH} will be
|
2021-10-05 15:50:41 +02:00
|
|
|
used only in the \uicontrol Design mode.
|
2019-04-08 16:56:13 +02:00
|
|
|
For an example, see \l {Qt Quick Controls - Contact List}.
|
2021-10-05 15:50:41 +02:00
|
|
|
\endif
|
2011-12-14 15:07:05 +01:00
|
|
|
*/
|