variant QML Basic Type
variant type is a generic property type. It is obsolete and exists only to support old applications; new applications should use var type properties instead.
A variant type property can hold any of the basic type values:
variant type property can also hold an image or pixmap. A
Clients may explicitly release such a scarce resource by calling the "destroy" method on the
variant type can also hold:
For example, below is an
items array and an
for loops. Individual array values are accessible by index, and individual map values are accessible by key:
While this is a convenient way to store array and map-type values, you must be aware that the
attributes are not QML properties. Rather, the
items property holds an array of values, and
attributes holds a set of key-value pairs. Since they are stored as a set of values, instead of as an object, their contents cannot be modified individually:
Since it is not possible to individually add or remove items from a list or object stored in a
variant, the only way to modify its contents is to reassign a new value. However, this is not efficient, as it causes the value to be serialized and deserialized.
attributes are not QML objects, changing their individual values do not trigger property change notifications. If the above example had
onAnimalChanged signal handlers, they would not have been called. If, however, the
attributes properties themselves were reassigned to different values, then such handlers would be called.
This basic type is provided by the QML language.
See also QML Basic Types.
© 2019 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.