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
property-override.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-property-override.html
6
\ingroup qmllint-warnings-and-errors
7
8
\title Property override
9
\brief [property-override] Wrong usage of override, final, and virtual keywords.
10
11
\qmllintwarningcategory property-override
12
13
\section1 Member does not override anything
14
15
\section2 What happened?
16
You marked a property as \c{override} without overriding anything. The base type of
17
the current component has no property of the same name marked as \c{virtual}.
18
19
\section2 Why is that bad?
20
The QML engine throws a runtime error when it encounters such a property.
21
22
\section2 Example
23
\qml
24
import QtQuick
25
26
Item {
27
component Base: Item { virtual property int myProperty; }
28
Base {
29
override property int myP: 42
30
}
31
}
32
\endqml
33
34
To fix this warning, you can:
35
\list
36
\li Remove the \c{override}-marker.
37
\li Double-check that the property name matches the name of a \c{virtual} or \c{override}
38
property in the base type of the current component.
39
\endlist
40
41
\qml
42
import QtQuick
43
44
Item {
45
component Base: Item { virtual property int myProperty; }
46
Base {
47
property int myP: 42 // solution 1: remove override
48
override property int myProperty: 42 // solution 2: fix spelling
49
}
50
}
51
\endqml
52
53
\section1 Member shadows final member
54
55
\section2 What happened?
56
You shadowed a property which is marked as final.
57
58
\section2 Why is that bad?
59
Properties are marked as final to prevent overriding and shadowing.
60
The QML engine throws a runtime error when it encounters the shadowing property.
61
62
\section2 Example
63
\qml
64
import QtQuick
65
66
Item {
67
component Base: Item { final property int myFinal; }
68
Base {
69
property int myFinal: 42
70
}
71
}
72
\endqml
73
74
To fix this warning, you can:
75
\list
76
\li Rename the shadowing or shadowed property.
77
\li Replace the \c{final} marker with \c{virtual} or \c{override} and add missing \c{override}
78
to the overriding property.
79
\endlist
80
81
\qml
82
import QtQuick
83
84
Item {
85
// solution 1: rename the property
86
component Base: Item { final property int myFinal; }
87
Base {
88
property int myFinal2: 42
89
}
90
91
// solution 2: replace the final marker and add override
92
component Base2: Item { virtual property int myFinal; }
93
Base2 {
94
override property int myFinal: 42
95
}
96
}
97
\endqml
98
99
\section1 Member overrides final member
100
101
\section2 What happened?
102
You overrode a property which is marked as final.
103
104
\section2 Why is that bad?
105
Properties marked as \c{final} prevent overriding and shadowing.
106
The QML engine throws a runtime error when it encounters the overriding property.
107
108
\section2 Example
109
\qml
110
import QtQuick
111
112
Item {
113
component Base: Item { final property int myFinal; }
114
Base {
115
override property int myFinal: 42
116
}
117
}
118
\endqml
119
120
To fix this warning, you can:
121
\list
122
\li Rename the shadowing or shadowed property, and remove the \c{override} marker.
123
\li Replace the \c{final} marker with \c{virtual} from the overridden property.
124
\endlist
125
126
\qml
127
import QtQuick
128
129
Item {
130
// solution 1: remove override and rename
131
component Base: Item { final property int myFinal; }
132
Base {
133
property int myFinal2: 42
134
}
135
136
// solution 2: replace final marker with virtual
137
component Base2: Item { virtual property int myFinal; }
138
Base2 {
139
override property int myFinal: 42
140
}
141
}
142
\endqml
143
144
\section1 Member shadows member
145
146
\section2 What happened?
147
You shadowed a \c{virtual} or \c{override} property without using \c{final}
148
or \c{override}.
149
150
\section2 Why is that bad?
151
Properties that shadow \c{virtual} properties need a \c{override} or \c{final} marker.
152
The QML engine throws a runtime warning when it encounters such a property.
153
154
\section2 Example
155
\qml
156
import QtQuick
157
158
Item {
159
component Base: Item { virtual property int myProperty; }
160
Base {
161
property int myProperty: 42
162
}
163
}
164
\endqml
165
166
To fix this warning, make the shadowing property \c{override} or \c{final}.
167
168
\qml
169
import QtQuick
170
171
Item {
172
component Base: Item { virtual property int myProperty; }
173
Base {
174
override property int myProperty: 42 // could also be final
175
}
176
}
177
\endqml
178
179
\section1 Member overrides a non-virtual member
180
181
\section2 What happened?
182
You overrode a property that was not marked as \c{virtual} or \c{override}.
183
184
\section2 Why is that bad?
185
Properties that can be overridden need to declare it via \c{virtual} or \c{override}.
186
The QML engine throws a runtime error when it encounters the overridden property missing
187
a \c{virtual} or \c{override} marker.
188
189
\section2 Example
190
\qml
191
import QtQuick
192
193
Item {
194
component Base: Item { property int myProperty; }
195
Base {
196
override property int myProperty: 42
197
}
198
}
199
\endqml
200
201
To fix this warning, rename the overriding property or mark the overridden property
202
as \c{virtual} or \c{override}.
203
204
\qml
205
import QtQuick
206
207
Item {
208
component Base: Item { virtual property int myProperty; }
209
Base {
210
override property int myProperty: 42
211
}
212
}
213
\endqml
214
215
\section1 Property already exists in base type
216
217
\section2 What happened?
218
You shadowed a property without using as \c{virtual}, \c{override}, or \c{final}.
219
220
\section2 Why is that bad?
221
Properties that can be overridden need to declare it via \c{virtual} or \c{override}.
222
The QML engine warns at runtime when it encounters the shadowing property.
223
224
\section2 Example
225
\qml
226
import QtQuick
227
228
Item {
229
component Base: Item { property int myProperty; }
230
Base {
231
property int myProperty: 42
232
}
233
}
234
\endqml
235
236
To fix this warning, rename the shadowing or shadowed property, or add the missing
237
\c{virtual}, \c{override}, or \c{final} markers.
238
239
\qml
240
import QtQuick
241
242
Item {
243
// solution 1: rename one of the properties
244
component Base: Item { property int myProperty; }
245
Base {
246
property int myProperty2: 42
247
}
248
249
// solution 2: add missing markers
250
component Base2: Item { virtual property int myProperty; }
251
Base2 {
252
final property int myProperty: 42 // could also be override
253
}
254
}
255
\endqml
256
*/
qtdeclarative
src
qml
doc
src
qmllint
property-override.qdoc
Generated on
for Qt by
1.16.1