Auf dieser Seite

Komponente fehlt eine erforderliche Eigenschaft

Diese Warnungskategorie wird von qmllint als „ [required] “ bezeichnet.

Der Komponente fehlt eine erforderliche Eigenschaft

Was ist passiert?

Die erforderliche Eigenschaft einer Komponente wurde nicht festgelegt.

Warum ist das ein Problem?

QML-Anwendungen, in denen Komponenten erforderliche Eigenschaften fehlen, verhalten sich fehlerhaft: Sie starten überhaupt nicht, wenn eine fehlende erforderliche Eigenschaft statisch erkannt wird. Dynamisch erstellte Komponenten mit fehlenden erforderlichen Eigenschaften werden zur Laufzeit nicht erstellt: Stattdessen sind sie null.

Beispiel

import QtQuick

Item {
    component RepeatMe: Item {
        required property int index;
        required property int helloWorld;
    }

    RepeatMe {} // not ok: required properties index and helloWorld not set

    Repeater {
        model: 10
        RepeatMe {} // not ok: required property index set by Repeater, but not helloWorld
    }
}

Um diese Warnung zu beheben, legen Sie die erforderlichen Eigenschaften fest:

import QtQuick

Item {
    component RepeatMe: Item {
        required property int index;
        required property int helloWorld;
    }

    RepeatMe {
        index: 0
        helloWorld: 42
    } // ok: all required properties were set

    Repeater {
        model: 10
        RepeatMe {
            helloWorld: index * 2 + 1
        } // ok: all required properties were set: index by the Repeater and helloWorld by the user
    }
}

Siehe auch QML-Codierungskonventionen – Erforderliche Eigenschaften.

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