Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 A component's required property was not bound.
10
11\section1 Component is Missing a Required Property
12
13\section2 What happened?
14The \l{QML Object Attributes#required-properties}{required property} of a component was not set.
15
16
17\section2 Why is this bad?
18QML applications where components miss required properties will misbehave: they will not
19start at all if a missing required property is detected statically. Dynamically created components
20with missing required properties will not be created at runtime: they will be null instead.
21
22\section2 Example
23\qml
24import QtQuick
25
26Item {
27 component RepeatMe: Item {
28 required property int index;
29 required property int helloWorld;
30 }
31
32 RepeatMe {} // not ok: required properties index and helloWorld not set
33
34 Repeater {
35 model: 10
36 RepeatMe {} // not ok: required property index set by Repeater, but not helloWorld
37 }
38}
39\endqml
40You can fix this warning by setting the required properties
41\qml
42import QtQuick
43
44Item {
45 component RepeatMe: Item {
46 required property int index;
47 required property int helloWorld;
48 }
49
50 RepeatMe {
51 index: 0
52 helloWorld: 42
53 } // ok: all required properties were set
54
55 Repeater {
56 model: 10
57 RepeatMe {
58 helloWorld: index * 2 + 1
59 } // ok: all required properties were set: index by the Repeater and helloWorld by the user
60 }
61}
62\endqml
63
64\sa {QML Coding Conventions#required-properties}{QML Coding Conventions - Required Properties}
65*/