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
Highlighted
Contributor
Posts: 29
Registered: ‎09-07-2012
My Device: 9900
My Carrier: Airtel

How to set multiple contextproperty for qml?

[ Edited ]

How to implement multiple contextproperty to qml? The below code i have tried, but i don't know about  is it correct or wrong.

 

LocationDiagnostics locationDiagnostics;
mQmlDocument = QmlDocument::create("asset:///main.qml").parent(this); QDeclarativeContext *derivedContext1 = new QDeclarativeContext(mQmlDocument->documentContext()); derivedContext1->setContextProperty("_app", this); Control *control1 = mQmlDocument->createRootObject<Control>(derivedContext1); QDeclarativeContext *derivedContext2 = new QDeclarativeContext(mQmlDocument->documentContext()); derivedContext2->setContextProperty("_locationDiagnostics", &locationDiagnostics); Control *control2 = mQmlDocument->createRootObject<Control>(derivedContext2);

 

Developer
Posts: 16,785
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to set multiple contextproperty for qml?

could you use the code tags to format code you post? it makes it easier to read.

the code you posted seems to be missing some, like the pointer to the created document (is it mQmlDocument?)

you call setContextProperty directly on the document, i your case i guess mQmlDocument.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter