继承周期

此警告类别由 qmllint 拼写为[inheritance-cycle]

组件是继承循环的一部分

发生了什么事?

组件直接或间接地从自身继承。

通常,组件可以从其他组件继承属性、方法、信号和枚举。

如果一个组件直接或间接地通过另一个基本组件继承自身,那么它就形成了一个继承循环。警告提示当前组件处于继承循环中,请参阅示例

为什么会出现这种情况?

带有继承循环的组件在运行时不会被创建:它们将被置为空。

示例

import QtQuick

Item {
    component Cycle: Cycle {} // not ok: directly inherits from itself
    component C: C2 {}        // not ok: indirectly inherits from itself
    component C2: C{}
}

要修复此警告,请打破继承循环:

import QtQuick

Item {
    component Cycle: Item {}  // ok: does not inherit from itself
    component C: C2 {}        // ok: does not indirectly inherits from itself anymore
    component C2: Cycle{}
}

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