In questa pagina

Preferire proprietà non-var

Questa categoria di avviso viene indicata da qmllint come " [prefer-non-var-properties] ".

Preferire un tipo più specifico rispetto a "var"

Cosa è successo?

Hai definito una proprietà in QML con il tipo " var " invece di uno più specifico, come ad esempio " int " o " string ".

Perché è un problema?

Questo compromette la leggibilità del codice e gli strumenti QML non possono applicare ottimizzazioni specifiche per il tipo.

Dovresti evitare di utilizzare var come tipo di proprietà per le proprietà che contengono sempre lo stesso tipo. Per evitare falsi positivi, qmllint segnala solo le proprietà di sola lettura con binding semplici. In altri casi, potrebbe non essere in grado di distinguere le proprietà che devono essere di tipo var, poiché devono contenere più tipi, dalle proprietà che contengono sempre lo stesso tipo.

Esempio

import QtQuick

Item {
    readonly property var myP: 42
}

Per correggere questo avviso, sostituire ` var ` con il tipo specifico.

import QtQuick

Item {
    readonly property int myP: 42
}

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