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