继承周期

组件属于继承周期

发生了什么?

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

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

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

为什么这不好?

具有继承周期的组件在运行时不会创建:它们将被置为 null。

示例

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{}
}

© 2024 The Qt Company Ltd. 本文档中的文档贡献的版权属于其各自的拥有者。本文档提供的文档是根据由自由软件基金会发布的 GNU 自由文档许可 1.3 版 的条款许可的。Qt 及其相应的标志是芬兰的 The Qt Company Ltd. 在世界其他国家的商标。所有其他商标均为其各自所有者的财产。