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\ingroup qmllint-warnings-and-errors
6
7\title Enums are not types
8\brief [enums-are-not-types] Enum names used as type annotations.
9
10\qmllintwarningcategory enums-are-not-types
11
12\section1 QML enumerations are not types
13
14\section2 What happened?
15You used an enum name inside a type annotation.
16
17\section2 Why is that bad?
18An enum name is not a type and therefore can't be used in a type annotation. QML tooling is
19not able to use the type annotation: the \l{Qt Quick Compiler}{compiler} can't compile this
20method to C++ and \l{qmllint} as well as \l{\QMLLS} can't analyze this method.
21
22\section2 Example
23\qml
24// Main.qml
25import QtQuick
26
27Item {
28 enum HelloWorld { Hello, World }
29 function f(e: Main.HelloWorld): bool {
30 return e == World
31 }
32}
33\endqml
34To fix this warning, replace the enum name in the type annotation with the underlying type,
35like \c{int} if the underlying type needs at most 32 bit, or otherwise \c{double}, for example.
36
37\qml
38import QtQuick
39
40Item {
41 enum HelloWorld { Hello, World }
42 function f(e: int): bool {
43 return e === World
44 }
45}
46\endqml
47*/