-moved delegate model related snippets from Qt Quick to Qt QML.
-corrected snippet paths
Change-Id: If688f97fb9317def16f343d5502a6a54d6761e95
Reviewed-by: Geir Vattekar <geir.vattekar@digia.com>
as a new QML type. It provides the current time through \c hour and \c minute
properties.
- \snippet qml/plugins/plugin.cpp 0
+ \snippet plugins/plugin.cpp 0
\dots
To make this type available, we create a plugin class named \c QExampleQmlPlugin
definition to register the plugin with the Qt meta object system using a unique
identifier for the plugin.
- \snippet qml/plugins/plugin.cpp plugin
+ \snippet plugins/plugin.cpp plugin
The \c TimeModel class receives a \c{1.0} version of this plugin library, as
a QML type called \c Time. The Q_ASSERT() macro can ensure the type namespace is
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:
- \quotefile qml/plugins/imports/TimeExample/qmldir
+ \quotefile plugins/imports/TimeExample/qmldir
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 qml/plugins/plugins.qml 0
+ \snippet plugins/plugins.qml 0
The full source code is available in the \l {qml/plugins}{plugins example}.
These extensions allow custom QML types to be made available to the QML engine.
To write a QML extension plugin:
-
+
\list
\li Subclass QQmlExtensionPlugin, implement registerTypes() method to register types
using qmlRegisterType(), and export the class using the Q_PLUGIN_METADATA() macro
as a new QML element. It provides the current time through \c hour and \c minute
properties, like this:
- \snippet qml/plugins/plugin.cpp 0
+ \snippet plugins/plugin.cpp 0
\dots
To make this class available as a QML type, create a plugin that registers
module will be named \c TimeExample (as defined in the project
file further below).
- \snippet qml/plugins/plugin.cpp plugin
+ \snippet plugins/plugin.cpp plugin
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
should be bundled with the plugin, so it needs to be specified in the \c qmldir
file:
- \quotefile qml/plugins/imports/TimeExample/qmldir
+ \quotefile plugins/imports/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 TimeExample module:
- \snippet qml/plugins/plugins.qml 0
+ \snippet plugins/plugins.qml 0
The full source code is available in the \l {qml/plugins}{plugins example}.
The example below illustrates using a DelegateModel with a ListView.
- \snippet qml/visualdatamodel.qml 0
+ \snippet delegatemodel/visualdatamodel.qml 0
*/
QQmlDelegateModelPrivate::QQmlDelegateModelPrivate(QQmlContext *ctxt)
the new directory's contents.
\c main.cpp:
- \snippet qml/visualdatamodel_rootindex/main.cpp 0
+ \snippet delegatemodel/visualdatamodel_rootindex/main.cpp 0
\c view.qml:
- \snippet qml/visualdatamodel_rootindex/view.qml 0
+ \snippet delegatemodel/visualdatamodel_rootindex/view.qml 0
If the \l model is a QAbstractItemModel subclass, the delegate can also
reference a \c hasModelChildren property (optionally qualified by a
The following example illustrates using groups to select items in a model.
- \snippet qml/visualdatagroup.qml 0
+ \snippet delegatemodel/visualdatagroup.qml 0
*/
QQmlListProperty<QQmlDelegateModelGroup> QQmlDelegateModel::groups()