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