| qqmlpropertymap.cpp |
!
\class QQmlPropertyMap
\brief The QQmlPropertyMap class allows you to set key-value pairs that can be used in QML bindings.
\inmodule QtQml
QQmlPropertyMap provides a convenient way to expose domain data to the UI layer.
The following example shows how you might declare data in C++ and then
access it in QML.
In the C++ file:
\code
// create our data
QQmlPropertyMap ownerData;
ownerData.insert("name", QVariant(QString("John Smith")));
ownerData.insert("phone", QVariant(QString("555-5555")));
// expose it to the UI layer
QQuickView view;
QQmlContext *ctxt = view.rootContext();
ctxt->setContextProperty("owner", &ownerData);
view.setSource(QUrl::fromLocalFile("main.qml"));
view.show();
\endcode
Then, in \c main.qml:
\code
Text { text: owner.name + " " + owner.phone }
\endcode
The binding is dynamic - whenever a key's value is updated, anything bound to that
key will be updated as well.
To detect value changes made in the UI layer you can connect to the valueChanged() signal.
However, note that valueChanged() is \b NOT emitted when changes are made by calling insert()
or clear() - it is only emitted when a value is updated from QML.
\note It is not possible to remove keys from the map; once a key has been added, you can only
modify or clear its associated value.
\note When deriving a class from QQmlPropertyMap, use the
\l {QQmlPropertyMap::QQmlPropertyMap(DerivedType *derived, QObject *parent)} {protected two-argument constructor}
which ensures that the class is correctly registered with the Qt \l {Meta-Object System}.
\note The QMetaObject of a QQmlPropertyMap is dynamically generated and modified.
Operations on that meta object are not thread safe, so applications need to take
care to explicitly synchronize access to the meta object.
|
11239 |
- |
| qqmlpropertymap.h |
|
2539 |
- |
| qqmlpropertyutils_p.h |
|
815 |
- |