I just want to know what this QtObject elements does, its seems that is reactive, because in the tutorial that I followed, use it for update the color of a button, so, I want to know how I can use it, and how its works, and how I can use in other cases.
2 Answers
while your are working on QML file need to hide some properties from upper layer Item ( some thing's like private variable and methods). best case for get a right way for incapsulation in QML is to using a internal item like QtObject . in your code used a QtObject for block the external direct access to button color and bind the color to the button item state.

- 514
- 2
- 12
I assume you've read the docs? A QtObject
is just the most basic type of of QML object. It doesn't do anything by itself. It's not visual. So it's just used for holding other properties.
In the example you provided, it's being used as a way to make pseudo-private variables. QML has no such thing as private variables, but if you put properties inside of an object, then they are not accessible to anything outside of this file (unless explicitly exposed). That's all it's being used for in your example. If you took the property dynamicColor
and moved it outside of the QtObject
, the code would still work exactly the same way. The only difference would be other QML files would be able to access (and therefore modify) dynamicColor
.

- 7,589
- 1
- 10
- 25