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
syntax.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 Syntax
8
\brief [syntax] Various syntactic errors.
9
10
\qmllintwarningcategory syntax
11
12
\section1 Nested inline components are not supported
13
14
\section2 What happened?
15
You defined an \l{qtqml-documents-definetypes.html#inline-components}{inline component}
16
inside another inline component.
17
18
\section2 Why is this bad?
19
The QML language does not allow nested inline components. Always define inline components
20
inside the root item of the QML file.
21
22
\section2 Example
23
\qml
24
import QtQuick
25
26
Item {
27
component Correct: Item {
28
component Evil: Item { ... }
29
...
30
}
31
}
32
33
\endqml
34
To fix this warning, move all components to the root item of the QML file.
35
\qml
36
import QtQuick
37
38
Item {
39
component NotEvilAnymore: Item { ... }
40
component Correct: Item {
41
...
42
}
43
}
44
45
\endqml
46
47
\section1 Inline component declaration must be followed by a typename
48
49
\section2 What happened?
50
You defined an \l{qtqml-documents-definetypes.html#inline-components}{inline component}
51
with an invalid base type.
52
53
\section2 Why is this bad?
54
Inline components need a base type to inherit from.
55
56
\section2 Example
57
\qml
58
import QtQuick
59
60
Item {
61
property Item someProperty
62
component InlineComponent: someProperty {}
63
}
64
65
\endqml
66
In this case, \c someProperty is not a valid type name, as it is a property name.
67
To fix this warning, use a valid Type as the component's base type:
68
\qml
69
import QtQuick
70
71
Item {
72
property Item someProperty
73
component InlineComponent: Item { ... }
74
}
75
76
\endqml
77
78
\section1 Invalid alias expression: an initializer is needed
79
80
\section2 What happened?
81
You defined a \l{qtqml-syntax-objectattributes.html#property-aliases}{property alias}
82
without its aliased property.
83
84
\section2 Why is this bad?
85
Alias properties always need to have their aliased property or id in their definition.
86
87
\section2 Example
88
\qml
89
import QtQuick
90
91
Item {
92
id: root
93
property int someProperty
94
property alias aliasProperty
95
}
96
97
\endqml
98
To fix this warning, replace the alias with a normal property, or add the missing
99
aliased property:
100
\qml
101
import QtQuick
102
103
Item {
104
id: root
105
property int someProperty
106
property alias withAliasedProperty: root.someProperty
107
}
108
109
\endqml
110
111
\section1 Invalid alias expression: only ids and field member expressions can be aliased
112
113
\section2 What happened?
114
You defined a \l{qtqml-syntax-objectattributes.html#property-aliases}{property alias}
115
that aliases an expression other than an ID or a field member expression.
116
117
A field member expression is an expression of the form \c {someId.someProperty}.
118
119
\section2 Why is this bad?
120
Alias properties always need to have their aliased property in their definition, and can't
121
bind to other expressions than IDs and field member expressions.
122
123
\section2 Example
124
\qml
125
import QtQuick
126
127
Item {
128
property int p
129
property alias someProperty: p + 1
130
}
131
132
\endqml
133
To fix this warning, replace the alias with a normal property or bind it to an id or
134
field member expression:
135
\qml
136
import QtQuick
137
138
Item {
139
id: root
140
property int p
141
property int someProperty: p + 1
142
property alias alternative: root.p
143
}
144
145
\endqml
146
147
\section1 Id must be followed by an identifier
148
149
\section2 What happened?
150
You defined an \l{qtqml-syntax-objectattributes.html#the-id-attribute}{id} without
151
a value.
152
153
\section2 Why is this bad?
154
The QML language does not allow empty ids.
155
156
\section2 Example
157
\qml
158
import QtQuick
159
160
Item {
161
id:;
162
}
163
164
\endqml
165
To fix this warning, bind the id to a valid name:
166
\qml
167
import QtQuick
168
169
Item {
170
id: root;
171
}
172
173
\endqml
174
175
\section1 Failed to parse id
176
177
\section2 What happened?
178
You bound an \l{qtqml-syntax-objectattributes.html#the-id-attribute}{id} to an
179
expression other than a name.
180
181
\section2 Why is this bad?
182
The QML language only allows names as bindings to ids; more complex expressions
183
can't be used.
184
185
\section2 Example
186
\qml
187
import QtQuick
188
189
Item {
190
property int a
191
property int b
192
function f() {
193
if (true)
194
return a
195
return b
196
}
197
198
id: f()
199
}
200
\endqml
201
To fix this warning, bind the id to a valid name or declare a property and set up a binding:
202
\qml
203
import QtQuick
204
205
Item {
206
property int a
207
property int b
208
function f() {
209
if (true)
210
return a
211
return b
212
}
213
214
id: someItem // it would be confusing to call it `f` like the function
215
property int alternative: f()
216
}
217
\endqml
218
219
\section1 Declaring an object which is not a QML object as a list member
220
221
\section2 What happened?
222
You added an expression other than an \l{qtqml-typesystem-objecttypes.html}{object} into a
223
list of objects.
224
225
\section2 Why is this bad?
226
The QML language only allows objects in object lists.
227
228
\section2 Example
229
\qml
230
import QtQuick
231
232
Item {
233
property int hello
234
property list<Item> myList: [
235
Item {}, hello{}
236
]
237
}
238
239
\endqml
240
To fix this warning, use a valid object type, or remove the item from the list:
241
\qml
242
import QtQuick
243
244
Item {
245
component Hello: Item {}
246
property list<Item> myList: [
247
Item {}, Hello{}
248
]
249
}
250
251
\endqml
252
253
\section1 Unknown argument to pragma
254
255
\section2 What happened?
256
You specified an invalid argument to a \l{qtqml-documents-structure.html#pragmas}{pragma}.
257
258
\section2 Why is this bad?
259
The pragma will have no effect.
260
261
\section2 Example
262
\qml
263
pragma ComponentBehavior: Buond
264
import QtQuick
265
266
Item {
267
}
268
269
\endqml
270
You can fix this warning by removing the pragma or fixing a potential typo:
271
\qml
272
pragma ComponentBehavior: Bound
273
import QtQuick
274
275
Item {
276
}
277
278
\endqml
279
*/
qtdeclarative
src
qml
doc
src
qmllint
syntax.qdoc
Generated on
for Qt by
1.16.1