In questa pagina

Proprietà mancante

Questa categoria di avviso viene indicata da qmllint con il nome " [missing-property] ".

Impossibile assegnare un valore a una proprietà predefinita inesistente

Cosa è successo?

Hai assegnato un oggetto a una proprietà predefinita inesistente.

Perché è un problema?

Il motore QML non può assegnare questo oggetto in fase di esecuzione.

Esempio

import QtQuick

Item {
    component MyType: QtObject { property Item myItem; }

    MyType {
        Item {}
    }
}

Per risolvere questo avviso, specifica la proprietà a cui desideri effettuare il binding oppure, se sei l'autore del tipo, contrassegna una proprietà come predefinita:

import QtQuick

Item {
    component MyType: QtObject { property Item myItem; }

    MyType {
        myItem: Item {}
    }

    component AlternativeMyType: QtObject { default property Item myItem; }

    AlternativeMyType {
        Item {} // bound to myItem via default property
    }
}

La proprietà non esiste

Cosa è successo?

Hai assegnato un'espressione a una proprietà inesistente.

Perché è un problema?

Il motore QML non può assegnare questa espressione in fase di esecuzione.

Esempio

import QtQuick

Item {
    property int myInt
    myItn: 42
}

Per risolvere questo avviso, rimuovi il binding o correggi un eventuale errore di battitura:

import QtQuick

Item {
    property int myInt
    myInt: 42
}

Membro non trovato nel tipo

Cosa è successo?

Si è effettuato l'accesso a un membro in un'espressione di membro di campo che non può essere individuata dagli strumenti QML. Un'espressione di membro di campo è un'espressione della forma someId.someProperty.

Il membro potrebbe non esistere affatto, ad esempio in caso di errore di digitazione. Oppure potrebbe esistere in fase di esecuzione (poiché presente in un sottotipo specifico sempre presente), ma non nel tipo dichiarato staticamente.

Perché è un problema?

Gli strumenti QML non riescono a individuare questo membro, il che significa che funzionalità come "vai alla definizione" e il completamento automatico non funzioneranno. In fase di esecuzione, potrebbe verificarsi un errore o si potrebbe ottenere un risultato errato se il membro non esiste realmente. Non ci sarà alcun errore se il membro esiste effettivamente sempre in fase di esecuzione; tuttavia, in tal caso, potrebbe comunque esserci un costo in termini di prestazioni dovuto alle ottimizzazioni mancanti.

Esempio

La proprietà non esiste effettivamente

import QtQuick

Item {
    id: self
    property int myInt
    property int myInt2: 1 + self.myItn
}

Per risolvere questo avviso, rimuovere il binding o correggere un eventuale errore di battitura:

import QtQuick

Item {
    id: self
    property int myInt
    property int myInt2: 1 + self.myInt
}

La proprietà esiste, ma il tipo non è sufficientemente preciso

import QtQuick
import QtQuick.Controls.Basic

Item {
  component Message : Item {
    required property string sender
    required property string text
  }
  ListView {
    id: messageView
    delegate: Message {}
  }

  Button {
    text: "Reply to %1".arg(messageView.currentItem.sender) // not ok
  }
}

Per risolvere questo avviso, eseguire il cast dell’oggetto da cui si sta leggendo in un tipo più specifico:

import QtQuick
import QtQuick.Controls.Basic

Item {
  component Message : Item {
    required property string sender
    required property string text
  }
  ListView {
    id: messageView
    delegate: Message {}
  }

  Button {
    text: "Reply to %1".arg((messageView.currentItem as Message).sender) // now ok
  }
}

Nell'esempio, il tipo dichiarato della proprietà currentItem di messageView è Item, che non possiede la proprietà sender: sender è definito solo in Message. In questo caso, tuttavia, sappiamo che currentItem contiene sempre un Message, quindi possiamo convertire currentItem in Message utilizzando un'asserzione di tipo.

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