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