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
SnGupta
Posts: 11
Registered: ‎01-24-2013
My Device: BB10
My Carrier: Airtel

ACCESSING C++ VARIABLES IN QML/JAVASCRIPT

Hi All,

 

I am curious to know how do I access variables declared in c++ classes in QML. I read this by using set Context property we can bind object of a class with QML. Which help us to access public member function of that class, but

is there any way to access public variable as well?

 

Regards

Santosh Gupta

 

Please use plain text.
Developer
strobejb
Posts: 267
Registered: ‎10-15-2012
My Device: bb10 developer
My Carrier: Orange

Re: ACCESSING C++ VARIABLES IN QML/JAVASCRIPT

Not directly. You can use the Q_PROPERTY macro to define properties in your C++ object that are accessible from QML
Please use plain text.
Developer
dridk
Posts: 91
Registered: ‎09-25-2012
My Device: bb10 alpha
My Carrier: free

Re: ACCESSING C++ VARIABLES IN QML/JAVASCRIPT

[ Edited ]

And with getter method preceded by Q_INVOKABLE. For slot method, it's not necessary.
About Q_PROPERTY, just add something like :
Q_PROPERTY (int value READ getValue WRITE setValue NOTIFY valueChanged)
Then, you will have dynamic binding property.

You can use Q_ENUMS too, to set constante. 

 

a lover of Qt
Please use plain text.