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