aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc')
-rw-r--r--src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc120
1 files changed, 45 insertions, 75 deletions
diff --git a/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc b/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc
index 01e81e7c19..771d520f8a 100644
--- a/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc
+++ b/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc
@@ -1,21 +1,36 @@
-QQmlExtensionPlugin is a plugin interface that makes it possible to
+\l QQmlEngineExtensionPlugin is a plugin interface that lets you
create QML extensions that can be loaded dynamically into QML applications.
These extensions allow custom QML types to be made available to the
QML engine.
To write a QML extension plugin:
\list 1
-\li Subclass QQmlExtensionPlugin
- \list
- \li Use the Q_PLUGIN_METADATA() macro to register the plugin with
- the Qt meta object system
- \li Override the \l{QQmlExtensionPlugin::}{registerTypes()} method
- and call qmlRegisterType() to register the types to be exported
- by the plugin
- \endlist
-\li Write a project file for the plugin
-\li Create a \l{Module Definition qmldir Files}{qmldir file} to
- describe the plugin
+\li Subclass \l QQmlEngineExtensionPlugin and use the Q_PLUGIN_METADATA() macro
+ to register the plugin with the Qt meta object system.
+\li Use the \l QML_ELEMENT and \l QML_NAMED_ELEMENT() macros to declare
+ QML types.
+\li Configure your build file.
+
+ CMake:
+ \badcode
+ qt_add_qml_module(<target>
+ URI <my.import.name>
+ VERSION 1.0
+ QML_FILES <app.qml>
+ NO_RESOURCE_TARGET_PATH
+ )
+ \endcode
+
+ qmake:
+ \badcode
+ CONFIG += qmltypes
+ QML_IMPORT_NAME = <my.import.name>
+ QML_IMPORT_MAJOR_VERSION = <version>
+ \endcode
+\li If you're using qmake, create a
+ \l {Module Definition qmldir Files} {qmldir file} to describe the plugin.
+ Note that CMake will, by default, automatically generate the
+ \l {Module Definition qmldir Files} {qmldir file}.
\endlist
QML extension plugins are for either application-specific or library-like
@@ -23,72 +38,27 @@ plugins. Library plugins should limit themselves to registering types, as
any manipulation of the engine's root context may cause conflicts or other
issues in the library user's code.
-\section1 TimeExample QML extension plugin
+\note When using the CMake \l qt_add_qml_module API, a plugin will be generated
+automatically for you. It will take care of type registration.
+You only need to write a custom plugin if you have special
+requirements, such as registering custom image
+providers. In that case, pass
+\l{NO_GENERATE_PLUGIN_SOURCE} to the \c qt_add_qml_module
+call to disable the generation of the default plugin.
-Suppose there is a new \c TimeModel C++ class that should be made available
-as a new QML type. It provides the current time through \c hour and \c minute
-properties.
-
-\snippet qmlextensionplugins/plugin.cpp 0
-\dots
-
-To make this type available, we create a plugin class named \c QExampleQmlPlugin
-which is a subclass of \l QQmlExtensionPlugin. It overrides the
-\l{QQmlExtensionPlugin::}{registerTypes()} method in order to register the \c TimeModel
-type using qmlRegisterType(). It also uses the Q_PLUGIN_METADATA() macro in the class
-definition to register the plugin with the Qt meta object system using a unique
-identifier for the plugin.
-
-\snippet qmlextensionplugins/plugin.cpp plugin
-
-This registers the \c TimeModel class with version \c{1.0} of this plugin library, as
-a QML type called \c Time. The Q_ASSERT() macro can ensure the type namespace is
-imported correctly by any QML components that use this plugin. The
-\l{Defining QML Types from C++} article has more information about registering C++
-types into the runtime.
-
-\section1 Project settings for the plugin
-
-Additionally, the project file (\c .pro) defines the project as a plugin library,
-specifies it should be built into the \c imports/TimeExample directory, and registers
-the plugin target name and various other details:
+The linker might erroneously remove the generated type registration
+function as an optimization. You can prevent that by declaring a synthetic
+volatile pointer to the function somewhere in your code. If your module is
+called "my.module", you would add the forward declaration in global scope:
\code
-TEMPLATE = lib
-CONFIG += qt plugin
-QT += qml
-
-DESTDIR = imports/TimeExample
-TARGET = qmlqtimeexampleplugin
-SOURCES += qexampleqmlplugin.cpp
+void qml_register_types_my_module();
\endcode
-\section1 Plugin definition in the qmldir
-
-Finally, a \l{Module Definition qmldir Files}{qmldir file} is required
-in the \c imports/TimeExample directory to describe the plugin and the types that it
-exports. The plugin includes a \c Clock.qml file along with the \c qmlqtimeexampleplugin
-that is built by the project (as shown above in the \c .pro file) so both of these
-need to be specified in the \c qmldir file:
+Then add the following snippet of code in the implementation of any function
+that's part of the same binary as the registration:
-\quotefile qmlextensionplugins/imports/TimeExample/qmldir
-
-To make things easier for this example, the TimeExample source directory is in
-\c{imports/TimeExample}, and we build
-\l{Source, Build, and Install Directories}{in-source}. However, the structure
-of the source directory is not so important, as the \c qmldir file can specify
-paths to installed QML files.
-
-What is important is the name of the directory that the qmldir is installed
-into. When the user imports our module, the QML engine uses the
-\l{Contents of a Module Definition qmldir File}{module identifier}
-(\c TimeExample) to find the plugin, and so the directory in which it is
-installed must match the module identifier.
-
-Once the project is built and installed, the new \c Time component is
-accessible by any QML component that imports the \c TimeExample
-module
-
-\snippet qmlextensionplugins/plugins.qml 0
-
-The full source code is available in the \l {qmlextensionplugins}{plugins example}.
+\code
+volatile auto registration = &qml_register_types_my_module;
+Q_UNUSED(registration);
+\endcode