组件必须且仅有一个子元素
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.