W3cubDocs

/Qt 6.9

Component is missing a required property

This warning category is spelled [required] by qmllint.

Component is missing a required property

What happened?

The required property of a component was not set.

Why is this bad?

QML applications where components miss required properties will misbehave: they will not start at all if a missing required property is detected statically. Dynamically created components with missing required properties will not be created at runtime: they will be null instead.

Example

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

To fix this warning, set the required properties:

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

See also QML Coding Conventions - Required Properties.

© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-6.9/qmllint-warnings-and-errors-required.html