本页内容

继承循环

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

组件属于继承循环的一部分

发生了什么?

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

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

如果一个组件直接或通过另一个基组件间接继承了自身,则会形成一个继承循环。该警告表明当前组件处于继承循环之中,请参见示例。

这有什么问题?

存在继承循环的组件在运行时不会被创建:它们将被视为 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{}
}

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