On this page

Components must have exactly one child

This warning category is spelled [component-children-count] by qmllint.

Components must have exactly one child

What happened?

A Component has the wrong number of children. It must have exactly one.

Why is that bad?

The root component of the file won't be instantiable and will cause an error at runtime.

Example

Component {
    Rectangle {
        width: 50
        height: 50
        color: "red"
    }
    Rectangle {
        width: 50
        height: 50
        color: "blue"
    }
}

To fix this warning, make sure the component has exactly one child. If it is empty, add a child to it. If it contains multiple, either remove the excess children, or wrap the children into a single top-level child of the component.

Component {
    Item {
        Rectangle {
            width: 50
            height: 50
            color: "red"
        }
        Rectangle {
            width: 50
            height: 50
            color: "blue"
        }
    }
}

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.