In questa pagina

Gli enumeratori non sono tipi

Questa categoria di avviso viene indicata da qmllint com [enums-are-not-types].

Le enumerazioni QML non sono tipi

Cosa è successo?

Hai utilizzato il nome di un'enumerazione all'interno di un'annotazione di tipo.

Perché è un errore?

Un nome di enumerazione non è un tipo e pertanto non può essere utilizzato in un'annotazione di tipo. Gli strumenti QML non sono in grado di utilizzare l'annotazione di tipo: il compilatore non può compilare questo metodo in C++ e nemmeno qmllint QML Language Server non è in grado di analizzare questo metodo.

Esempio

// Main.qml
import QtQuick

Item {
    enum HelloWorld { Hello, World }
    function f(e: Main.HelloWorld): bool {
        return e == World
    }
}

Per risolvere questo avviso, sostituisci il nome dell'enumerazione nell'annotazione di tipo con il tipo sottostante, ad esempio int se il tipo sottostante richiede al massimo 32 bit, oppure double, a seconda dei casi.

import QtQuick

Item {
    enum HelloWorld { Hello, World }
    function f(e: int): bool {
        return e === World
    }
}

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