Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
enums-are-not-types.qdoc
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qmllint-warnings-and-errors-enums-are-not-types.html
6\ingroup qmllint-warnings-and-errors
7
8\title Enums are not types
9\brief [enums-are-not-types] Enum names used as type annotations.
10
11\qmllintwarningcategory enums-are-not-types
12
13\section1 QML enumerations are not types
14
15\section2 What happened?
16You used an enum name inside a type annotation.
17
18\section2 Why is that bad?
19An enum name is not a type and therefore can't be used in a type annotation. QML tooling is
20not able to use the type annotation: the \l{Qt Quick Compiler}{compiler} can't compile this
21method to C++ and \l{qmllint} as well as \l{\QMLLS} can't analyze this method.
22
23\section2 Example
24\qml
25// Main.qml
26import QtQuick
27
28Item {
29 enum HelloWorld { Hello, World }
30 function f(e: Main.HelloWorld): bool {
31 return e == World
32 }
33}
34\endqml
35To fix this warning, replace the enum name in the type annotation with the underlying type,
36like \c{int} if the underlying type needs at most 32 bit, or otherwise \c{double}, for example.
37
38\qml
39import QtQuick
40
41Item {
42 enum HelloWorld { Hello, World }
43 function f(e: int): bool {
44 return e === World
45 }
46}
47\endqml
48*/