Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
gdev001
Posts: 163
Registered: ‎01-30-2013
My Device: Blackberry 10 Simulator

QDeclarativePropertyMap and passing C++ object to QML

[ Edited ]

Hi,

 

this sample here https://developer.blackberry.com/cascades/documentation/dev/integrating_cpp_qml/index.html,

section: "Exposing C++ values and objects to QML", talks how to useQDeclarativePropertyMap to pass data to QML from C++. For example it shows how to add the key value pairs:

propertyMap->insert("name", QVariant(QString("Wes Barichak")));
propertyMap->insert("phone", QVariant(QString("519-555-0199")));

I am curious how would I be able to use this approach if I want to pass an array of objects to the propertyMap???

 

Same goes to the "Exposing C++ objects to QML" section on the same page.

They show how to pass cppObject to QML using:

 

MyCppClass *cppObject = new MyCppClass();
qml->setContextProperty("cppObject", cppObject);

 and then one can access cppObject from QML, but what to do if I want to

pass an array of say cppObjects to QML? What would I do in this case? and how
would I be able to access them from QML?
 
Thanks.

 

 

Thanks.

Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: QDeclarativePropertyMap and passing C++ object to QML

Hi,

 

Create a Q_INVOKABLE function returning QVariantList. It will work like JavaScript arrays in QML. QVariantMap can also be used.

 

Items in map can be iterated like this:

for (var key in myMap) {
  console.log(key, "=", myMap[key])
}

 


Andrey Fidrya, @zmeyc on twitter
Developer
gdev001
Posts: 163
Registered: ‎01-30-2013
My Device: Blackberry 10 Simulator

Re: QDeclarativePropertyMap and passing C++ object to QML

Hi thanks I seem not to be able to find documentation for QVariantList on the net, am I the only one like this? could you provide some links? thanks.
Developer
dishooom
Posts: 103
Registered: ‎12-31-2012
My Device: Blackberry 9810

Re: QDeclarativePropertyMap and passing C++ object to QML

Thats because, QvariantList is just  the typedef of  QList<QVariant>

 

See this http://qt-project.org/doc/qt-4.8/qvariant.html#QVariantList-typedef

 

So, may be you can take a look into QList for now.

 

 

_Dishooom

 

 

Hope this helps :Angel: