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
duplicate-property-binding.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2023 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 Duplicate bindings
8
\brief [duplicate-property-binding] A property was bound multiple times.
9
10
\qmllintwarningcategory duplicate-property-binding
11
12
\section1 Duplicate interceptor on property
13
14
\section2 What happened?
15
One property has multiple \l{Property Modifier Types}{interceptors}.
16
17
\section2 Why is this bad?
18
Setting multiple interceptors on the same property is unsupported by the QML engine.
19
20
\section2 Example
21
22
Lets use \l{Behavior} as interceptor twice on the same property:
23
\qml
24
import QtQuick
25
26
Rectangle {
27
Behavior on width {
28
NumberAnimation { duration: 1000 }
29
}
30
Behavior on width { // not ok: Duplicate interceptor on property "width" [duplicate-property-binding]
31
NumberAnimation { duration: 2000 }
32
}
33
}
34
\endqml
35
To fix this warning, remove all but one \l{Behavior}:
36
\qml
37
import QtQuick
38
39
Rectangle {
40
Behavior on width {
41
NumberAnimation { duration: 2000 }
42
}
43
}
44
\endqml
45
46
\b {See also} \l {Property Modifier Types}.
47
48
\section1 Duplicate value source on property
49
50
\section2 What happened?
51
One property has multiple \l{Property Value Sources}{value sources}.
52
53
\section2 Why is this bad?
54
The value sources will show unexpected behavior when combined. See the example below.
55
56
\section2 Example
57
58
Lets use \l{NumberAnimation} as value source twice on the same property:
59
\qml
60
import QtQuick
61
62
Rectangle {
63
NumberAnimation on x { to: 50; duration: 1000 }
64
NumberAnimation on x { to: 10; duration: 100 } // not ok: Duplicate value source on property "x" [duplicate-property-binding]
65
66
onXChanged: console.log(x)
67
}
68
\endqml
69
70
If you check the output of that program, you will see that the two NumberAnimation will interleave
71
each other, which is probably not the effect that was intended.
72
To fix this warning, remove all but one \l{NumberAnimation}:
73
\qml
74
import QtQuick
75
76
Rectangle {
77
NumberAnimation on x { to: 50; duration: 1000 }
78
}
79
\endqml
80
81
82
\section1 Cannot combine value source and binding
83
84
\section2 What happened?
85
One property has a \l{Property Value Sources}{value source} and a binding on the same property.
86
87
\section2 Why is this bad?
88
The binding will updated the property value before the value source starts updating this property.
89
This may lead to unexpected behavior, and is also harder to read.
90
91
\section2 Example
92
93
Lets use \l{NumberAnimation} as value source on the same property:
94
\qml
95
import QtQuick
96
97
Rectangle {
98
NumberAnimation on x { to: 50; duration: 1000 } // not ok: Cannot combine value source and binding on property "x" [duplicate-property-binding]
99
x: 55
100
101
onXChanged: console.log(x)
102
}
103
\endqml
104
105
If you check the output of that program, you will see that the \l{NumberAnimation} will animate
106
from 55 to 50, which would be easier to read with following code:
107
\qml
108
import QtQuick
109
110
Rectangle {
111
NumberAnimation on x { from: 55; to: 50; duration: 1000 } // ok: intentions are clearer now!
112
}
113
\endqml
114
115
*/
qtdeclarative
src
qml
doc
src
qmllint
duplicate-property-binding.qdoc
Generated on
for Qt by
1.16.1