在此页面上

类型被递归实例化

qmllint 将此警告类别拼写为[type-instantiated-recursively] 。

类型无法递归实例化

发生了什么?

某个组件实例化了自身。

为什么这样不好?

该组件需要自身来实例化自身,从而形成无限循环。QML Runtime会对此组件报错。

示例

// MyComponent.qml
import QtQuick

Item {
    MyComponent {}
}

要解决此警告,

// MyComponent.qml
import QtQuick

Item {
    // solution 1: MyComponent was not needed here, use another type
    Item {}

    // solution 2: add a MyComponent property and set it later
    property MyComponent myChild
}

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