Nesta página

Falta uma propriedade obrigatória no componente

Essa categoria de aviso é denominada “ [required] ” pelo qmllint.

O componente não possui uma propriedade obrigatória

O que aconteceu?

A propriedade obrigatória de um componente não foi definida.

Por que isso é ruim?

Aplicativos QML nos quais os componentes não possuem propriedades obrigatórias apresentarão comportamento indesejado: eles nem sequer iniciarão se uma propriedade obrigatória ausente for detectada estaticamente. Componentes criados dinamicamente com propriedades obrigatórias ausentes não serão criados em tempo de execução: em vez disso, serão nulos.

Exemplo

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

Para corrigir esse aviso, defina as propriedades obrigatórias:

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

Veja também Convenções de codificação do QML - Propriedades obrigatórias.

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