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
required.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-required.html
6
\ingroup qmllint-warnings-and-errors
7
8
\title Component is missing a required property
9
\brief [required] A component's required property was not bound.
10
11
\qmllintwarningcategory required
12
13
\section1 Component is missing a required property
14
15
\section2 What happened?
16
The \l{QML Object Attributes#required-properties}{required property} of a component was not set.
17
18
19
\section2 Why is this bad?
20
QML applications where components miss required properties will misbehave: they will not
21
start at all if a missing required property is detected statically. Dynamically created components
22
with missing required properties will not be created at runtime: they will be null instead.
23
24
\section2 Example
25
\qml
26
import QtQuick
27
28
Item {
29
component RepeatMe: Item {
30
required property int index;
31
required property int helloWorld;
32
}
33
34
RepeatMe {} // not ok: required properties index and helloWorld not set
35
36
Repeater {
37
model: 10
38
RepeatMe {} // not ok: required property index set by Repeater, but not helloWorld
39
}
40
}
41
\endqml
42
To fix this warning, set the required properties:
43
\qml
44
import QtQuick
45
46
Item {
47
component RepeatMe: Item {
48
required property int index;
49
required property int helloWorld;
50
}
51
52
RepeatMe {
53
index: 0
54
helloWorld: 42
55
} // ok: all required properties were set
56
57
Repeater {
58
model: 10
59
RepeatMe {
60
helloWorld: index * 2 + 1
61
} // ok: all required properties were set: index by the Repeater and helloWorld by the user
62
}
63
}
64
\endqml
65
66
\sa {QML Coding Conventions#required-properties}{QML Coding Conventions - Required Properties}
67
*/
qtdeclarative
src
qml
doc
src
qmllint
required.qdoc
Generated on
for Qt by
1.14.0