On this page

Prefer non-var properties

This warning category is spelled [prefer-non-var-properties] by qmllint.

Prefer more specific type over var

What happened?

You defined a property in QML with type var instead of a more specific one, like int or string for example.

Why is that bad?

This affects the readability of the code and the QML tooling can't apply specific type optimizations.

You should avoid using var as property type for properties that always holds the same type. To avoid false positives, qmllint only warns about readonly properties with simple bindings. In other cases, it may not be able to distinguish properties that have to be var, because they need to hold multiple types, from properties that always hold the same type.

Example

import QtQuick

Item {
    readonly property var myP: 42
}

To fix this warning, replace var with the specific type.

import QtQuick

Item {
    readonly property int myP: 42
}

© 2026 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.