Sur cette page

Les composants doivent avoir exactement un enfant

Cette catégorie d’avertissement est intitulée « [component-children-count] » par qmllint.

Les composants doivent avoir exactement un enfant

Que s'est-il passé ?

Un composant comporte un nombre incorrect d'enfants. Il doit en avoir exactement un.

Pourquoi est-ce un problème ?

Le composant racine du fichier ne pourra pas être instancié et provoquera une erreur lors de l'exécution.

Exemple

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

Pour corriger cet avertissement, assurez-vous que le composant possède exactement un enfant. S'il est vide, ajoutez-y un enfant. S'il en contient plusieurs, supprimez les enfants en trop ou regroupez-les dans un seul enfant de niveau supérieur du composant.

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.