- Qt 6.12
- Qt Qml
- QML Lint Warning and Errors
- Prefer non-var properties
- Qt 6.12.0 Reference Documentation

# 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
     }