Vererbungszyklus

Diese Warnkategorie wird von qmllint mit [inheritance-cycle] angegeben.

Komponente ist Teil eines Vererbungszyklus

Was ist passiert?

Eine Komponente hat direkt oder indirekt von sich selbst geerbt.

Normalerweise können Komponenten Eigenschaften, Methoden, Signale und Enums von anderen Komponenten erben.

Wenn eine Komponente sich selbst direkt oder indirekt über eine andere Basiskomponente erbt, dann bildet sie einen Vererbungszyklus. Die Warnung zeigt an, dass sich die aktuelle Komponente innerhalb eines Vererbungszyklus befindet, siehe Beispiel.

Warum ist das schlecht?

Komponenten mit Vererbungszyklen werden zur Laufzeit nicht erstellt: Sie sind stattdessen null.

Beispiel

import QtQuick

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

Um diese Warnung zu beheben, brechen Sie den Vererbungszyklus auf:

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.