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
Contributor
Posts: 44
Registered: ‎09-14-2012
My Device: BB 10 Dev alpha
My Carrier: -
Accepted Solution

Integer contextProperty or how convert int to QObject

How QObject can be created from int value?

I need it to set integer context property.

 

Thanks in advance,

Eugene

Contributor
Posts: 44
Registered: ‎09-14-2012
My Device: BB 10 Dev alpha
My Carrier: -

Re: Integer contextProperty or how convert int to QObject

[ Edited ]

Sorry, I already found the answer.

 

In this case we have to use QDeclarativeContext explicitly.

e.g.

int integerValue = 42;
QVariant qIntegerValue(integerValue);
QDeclarativeContext* context = |instantiate new or use exist|;
context->setContextProperty("intValue", qIntegerValue);

QmlDocument* doc = QmlDocument::create("you.qml");
Page* page = doc->createRootObject<Page>(context);

 

Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Integer contextProperty or how convert int to QObject

Could also define a property in your page qml file and do

 

page->setProperty("intProperty",QVariant::fromValue(integerValue))

Like all of my posts
Contributor
Posts: 44
Registered: ‎09-14-2012
My Device: BB 10 Dev alpha
My Carrier: -

Re: Integer contextProperty or how convert int to QObject

[ Edited ]

Thanks, it also the suitable solution.