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
component-children-count.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 Components must have exactly one child
8\brief [component-children-count] A component has the wrong number of children.
9
10\qmllintwarningcategory component-children-count
11
12\section1 Components must have exactly one child
13
14\section2 What happened?
15A Component has the wrong number of children. It must have exactly one.
16
17\section2 Why is that bad?
18The root component of the file won't be instantiable and will cause an error at
19runtime.
20
21\section2 Example
22\qml
23Component {
24 Rectangle {
25 width: 50
26 height: 50
27 color: "red"
28 }
29 Rectangle {
30 width: 50
31 height: 50
32 color: "blue"
33 }
34}
35\endqml
36To fix this warning, make sure the component has exactly one child. If it is
37empty, add a child to it. If it contains multiple, either remove the excess
38children, or wrap the children into a single top-level child of the component.
39\qml
40Component {
41 Item {
42 Rectangle {
43 width: 50
44 height: 50
45 color: "red"
46 }
47 Rectangle {
48 width: 50
49 height: 50
50 color: "blue"
51 }
52 }
53}
54\endqml
55*/