En esta página

Los componentes deben tener exactamente un elemento secundario

qmllint denomina esta categoría de advertencia « [component-children-count] ».

Los componentes deben tener exactamente un elemento secundario

¿Qué ha pasado?

Un componente tiene un número incorrecto de elementos secundarios. Debe tener exactamente uno.

¿Por qué es un problema?

El componente raíz del archivo no se podrá instanciar y provocará un error en tiempo de ejecución.

Ejemplo

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

Para solucionar esta advertencia, asegúrate de que el componente tenga exactamente un elemento secundario. Si está vacío, añádele uno. Si contiene varios, elimina los elementos secundarios sobrantes o agrupa todos los elementos secundarios en un único elemento secundario de nivel superior del componente.

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.