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