Porting to Qt 6 - Qt QML
Qt 6 is a result of the conscious effort to make the framework more efficient and easy to use.
We try to maintain binary and source compatibility for all the public APIs in each release. But some changes were inevitable in an effort to make Qt a better framework.
In this topic we summarize those changes in Qt QML, and provide guidance to handle them.
QML language
variant
properties, which have been marked as obsolete since Qt 5, are now treated in exactly the same way as var
properties. Code that relied on implicit string conversion triggered on assignment to variant properties should be updated to explicitly create an object of the correct type.
For example, if you have code like
property variant myColor: "red"
you can rewrite it as
property variant myColor: Qt.color("red")
Implicit conversions were done for strings that could be parsed as
- color (use Qt.color instead instead),
- date (use the Date object instead),
- rect (use Qt.rect instead) and
- size (use Qt.size instead)
variant
still remains a deprecated keyword in Qt 6, though new code is strongly encouraged to use var
properties instead.
Note: If the type of the property is known not to change, use a property of the concrete type, instead of a var
property.
Note: These conversions were also applied to QVariant
properties of classes registered with the engine. As with variant
properties, code that relied on implicit string conversions need to use the corresponding functions of the Qt object.