PDA

View Full Version : read-only property in qml



sajis997
1st January 2015, 14:01
Hello forum,

I need a read-only property available in qml. Do I have to define a notify signal ? Consider the following scenario:



Q_PROPERTY(float maxPatchVertices READ maxPatchVertices NOTIFY maxPatchVerticesChanged)


Above i need to retrive the value from the underlying C++ object and make it available to qml. Can i define the above snippet as follows instead:



Q_PROPERTY(float maxPatchVertices READ maxPatchVertices)



Thanks

anda_skoa
1st January 2015, 14:59
You need a NOTIFY signal if the value of the property can change during runtime, in order to allow the QML engine to update property bindings. This is independent of whether QML can write to the property.

If the value can not change t all, then mark the property as CONSTANT.

Cheers,
_

sajis997
1st January 2015, 15:57
The value never changes inside the QML. it is set once druing the opengl initialization and read in by one of the qt quick controls - slider maximumValue. When i assign value to the slider , i am getting 0. This is not correct. It seems that the Qt property system is getting initialized before the back-end opengl initialization

anda_skoa
1st January 2015, 17:42
The value never changes inside the QML. it is set once druing the opengl initialization and read in by one of the qt quick controls - slider maximumValue.

Yes, you already wrote that it is a read-only property.
It is even in the thread's title.



When i assign value to the slider , i am getting 0. This is not correct. It seems that the Qt property system is getting initialized before the back-end opengl initialization
The property system is not "initialized", see other thread.

If you get 0 as the value of the property, then 0 is what the property's getter function returns. If that is not the right value, fix the getter function.

Cheers,
_