Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
prefer-non-var-properties.qdoc
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\ingroup qmllint-warnings-and-errors
6
7\title Prefer non-var properties
8\brief [prefer-non-var-properties] Prefer non-var properties over var properties.
9
10\qmllintwarningcategory prefer-non-var-properties
11
12\section1 Prefer more specific type over var
13
14\section2 What happened?
15You defined a property in QML with type \c{var} instead of a more specific one,
16like \c{int} or \c{string} for example.
17
18\section2 Why is that bad?
19This affects the readability of the code and the QML tooling can't apply specific
20type optimizations.
21
22You should avoid using \c{var} as property type for properties that always holds
23the same type. To avoid false positives, qmllint only warns about readonly
24properties with simple bindings. In other cases, it may not be able to
25distinguish properties that have to be var, because they need to hold multiple types,
26from properties that always hold the same type.
27
28\section2 Example
29\qml
30import QtQuick
31
32Item {
33 readonly property var myP: 42
34}
35\endqml
36To fix this warning, replace \c{var} with the specific type.
37\qml
38import QtQuick
39
40Item {
41 readonly property int myP: 42
42}
43\endqml
44*/