diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-08-06 06:32:19 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-08-06 06:34:05 (GMT) |
commit | 59e3430662cfdc3820115a2ff4c0b44829b3d1d4 (patch) | |
tree | cc8a1b0027f7df5f9bd0025f32545851ac61e152 | |
parent | 94b1c07c31ab84d30b198cb23291a48f98164827 (diff) | |
download | Qt-59e3430662cfdc3820115a2ff4c0b44829b3d1d4.zip Qt-59e3430662cfdc3820115a2ff4c0b44829b3d1d4.tar.gz Qt-59e3430662cfdc3820115a2ff4c0b44829b3d1d4.tar.bz2 |
Fix broken example code
Task-number: QTBUG-12705
-rw-r--r-- | src/declarative/util/qdeclarativepropertymap.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/declarative/util/qdeclarativepropertymap.cpp b/src/declarative/util/qdeclarativepropertymap.cpp index 919727f..6b43040 100644 --- a/src/declarative/util/qdeclarativepropertymap.cpp +++ b/src/declarative/util/qdeclarativepropertymap.cpp @@ -104,22 +104,25 @@ void QDeclarativePropertyMapMetaObject::propertyCreated(int, QMetaPropertyBuilde The following example shows how you might declare data in C++ and then access it in QML. - Setup in C++: + In the C++ file: \code - //create our data + // create our data QDeclarativePropertyMap ownerData; ownerData.insert("name", QVariant(QString("John Smith"))); ownerData.insert("phone", QVariant(QString("555-5555"))); - //expose it to the UI layer - QDeclarativeContext *ctxt = view->rootContext(); - ctxt->setProperty("owner", &data); + // expose it to the UI layer + QDeclarativeView view; + QDeclarativeContext *ctxt = view.rootContext(); + ctxt->setContextProperty("owner", &ownerData); + + view.setSource(QUrl::fromLocalFile("main.qml")); + view.show(); \endcode - Then, in QML: + Then, in \c main.qml: \code - Text { text: owner.name } - Text { text: owner.phone } + Text { text: owner.name + " " + owner.phone } \endcode The binding is dynamic - whenever a key's value is updated, anything bound to that |