QT_BEGIN_NAMESPACE
/*!
- \since 4.7
+ \since 5.0
+ \inmodule QtQml
\class QQmlExtensionPlugin
\brief The QQmlExtensionPlugin class provides an abstract base for custom QML extension plugins.
To write a QML extension plugin:
\list
- \o Subclass QQmlExtensionPlugin, implement registerTypes() method
+ \li Subclass QQmlExtensionPlugin, implement registerTypes() method
to register types using qmlRegisterType(), and export the class using the Q_EXPORT_PLUGIN2() macro
- \o Write an appropriate project file for the plugin
- \o Create a \l{Writing a qmldir file}{qmldir file} to describe the plugin
+ \li Write an appropriate project file for the plugin
+ \li Create a \l{Module Definition qmldir Files}{qmldir file} to describe the plugin
\endlist
QML extension plugins can be used to provide either application-specific or
as a new QML element. It provides the current time through \c hour and \c minute
properties, like this:
- \snippet examples/declarative/cppextensions/plugins/plugin.cpp 0
+ \snippet examples/qml/cppextensions/plugins/plugin.cpp 0
\dots
To make this class available as a QML type, create a plugin that registers
module will be named \c com.nokia.TimeExample (as defined in the project
file further below).
- \snippet examples/declarative/cppextensions/plugins/plugin.cpp plugin
+ \snippet examples/qml/cppextensions/plugins/plugin.cpp plugin
\codeline
- \snippet examples/declarative/cppextensions/plugins/plugin.cpp export
+ \snippet examples/qml/cppextensions/plugins/plugin.cpp export
This registers the \c TimeModel class with the 1.0 version of this
plugin library, as a QML type called \c Time. The Q_ASSERT statement
\code
TEMPLATE = lib
CONFIG += qt plugin
- QT += declarative
+ QT += qml
DESTDIR = com/nokia/TimeExample
TARGET = qmlqtimeexampleplugin
...
\endcode
- Finally, a \l{Writing a qmldir file}{qmldir file} is required in the \c com/nokia/TimeExample directory
+ Finally, a \l{Module Definition qmldir Files}{qmldir file} is required in the \c com/nokia/TimeExample directory
that describes the plugin. This directory includes a \c Clock.qml file that
should be bundled with the plugin, so it needs to be specified in the \c qmldir
file:
- \quotefile examples/declarative/cppextensions/plugins/com/nokia/TimeExample/qmldir
+ \quotefile examples/qml/cppextensions/plugins/com/nokia/TimeExample/qmldir
Once the project is built and installed, the new \c Time element can be
used by any QML component that imports the \c com.nokia.TimeExample module:
- \snippet examples/declarative/cppextensions/plugins/plugins.qml 0
+ \snippet examples/qml/cppextensions/plugins/plugins.qml 0
- The full source code is available in the \l {declarative/cppextensions/plugins}{plugins example}.
+ The full source code is available in the \l {qml/cppextensions/plugins}{plugins example}.
- The \l {Tutorial: Writing QML extensions with C++} also contains a chapter
+ The \l {Writing QML Extensions with C++} tutorial also contains a chapter
on creating QML plugins.
+ Note that the QtQuick 1 version is called QDeclarativeExtensionPlugin.
+
\sa QQmlEngine::importPlugin(), {How to Create Qt Plugins}
*/