このページについて

列挙型は型ではありません

qmllint では、この警告カテゴリは「[enums-are-not-types] 」と表記されます。

QMLの列挙型は型ではありません

何が起きたのか?

型アノテーション内で列挙型の名前を使用しました。

なぜ問題なのでしょうか?

列挙型の名前は型ではないため、型注釈内で使用することはできません。QML ツールはこの型注釈を使用できません。コンパイラはこのメソッドをC++ にコンパイルできず、qmllintも同様に QML Language Server このメソッドを解析することもできません。

例

// Main.qml
import QtQuick

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

この警告を修正するには、型注釈内の列挙型名を、基礎となる型に置き換えてください。例えば、基礎となる型が最大 32 ビットを必要とする場合は `int `、それ以外の場合は `double` のようにします。

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.