本页内容

顶级组件

qmllint 将此警告类别拼写为[top-level-component] 。

QML 顶级类型不能是Component

发生了什么?

您将Component 类型用作QML文件的顶级类型。

为什么这样不好?

您的 QML 文件本身已经定义了一个组件。将 `Component ` 类型用作顶级类型会将您的组件包裹进另一个不必要的组件中。

示例

import QtQuick

Component {
    Item { ... }
}

要解决此警告,请移除多余的 Component 包装:

import QtQuick

Item { ... }

© 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.