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