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
\page qmllint-warnings-and-errors-prefer-non-var-properties.html
6
\ingroup qmllint-warnings-and-errors
7
8
\title Prefer non-var properties
9
\brief [prefer-non-var-properties] Prefer non-var properties over var properties.
10
11
\qmllintwarningcategory prefer-non-var-properties
12
13
\section1 Prefer more specific type over var
14
15
\section2 What happened?
16
You defined a property in QML with type \c{var} instead of a more specific one,
17
like \c{int} or \c{string} for example.
18
19
\section2 Why is that bad?
20
This affects the readability of the code and the QML tooling can't apply specific
21
type optimizations.
22
23
You should avoid using \c{var} as property type for properties that always holds
24
the same type. To avoid false positives, qmllint only warns about readonly
25
properties with simple bindings. In other cases, it may not be able to
26
distinguish properties that have to be var, because they need to hold multiple types,
27
from properties that always hold the same type.
28
29
\section2 Example
30
\qml
31
import QtQuick
32
33
Item {
34
readonly property var myP: 42
35
}
36
\endqml
37
To fix this warning, replace \c{var} with the specific type.
38
\qml
39
import QtQuick
40
41
Item {
42
readonly property int myP: 42
43
}
44
\endqml
45
*/
qtdeclarative
src
qml
doc
src
qmllint
prefer-non-var-properties.qdoc
Generated on
for Qt by
1.16.1