组件必须有一个子组件
此警告类别由 qmllint 拼写为[component-children-count] 。
组件必须正好有一个子组件
发生了什么事?
一个组件的子组件数量不对。它必须正好有一个。
为什么会这样?
文件的根组件将不可实例化,并会在运行时出错。
示例
Component { 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.