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
enum-key-case.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-enum-key-case.html
6
\ingroup qmllint-warnings-and-errors
7
8
\title Enum key case
9
\brief [enum-key-case] Enum key starts with a lowercase letter
10
11
\qmllintwarningcategory enum-key-case
12
13
\section1 Enum key starts with a lowercase letter
14
15
\section2 What happened?
16
An enum contains a key starting with a lowercase letter.
17
18
\section2 Why is that bad?
19
It can create ambiguity when performing lookups. Enum keys should start with an uppercase letter
20
to distinguish them from properties of singletons and attached objects. Not following this
21
convention can lead to unexpected results.
22
23
\section2 Example
24
\qml
25
// Properties.qml
26
import QtQuick
27
28
Item {
29
enum Color { red, green, blue }
30
}
31
\endqml
32
\qml
33
// Main.qml
34
import QtQuick
35
36
Item {
37
// This lookup could be interpreted as a property lookup on a Singleton or attached object.
38
property int i: Properties.green
39
}
40
\endqml
41
42
To fix this warning, rename the key so it starts with an uppercase letter.
43
44
\qml
45
// Properties.qml
46
import QtQuick
47
48
Item {
49
enum Color { Red, Green, Blue }
50
}
51
\endqml
52
\qml
53
// Main.qml
54
import QtQuick
55
56
Item {
57
// No ambiguity for the user or the QML engine, this is an enum lookup.
58
property int i: Properties.Green
59
}
60
\endqml
61
*/
qtdeclarative
src
qml
doc
src
qmllint
enum-key-case.qdoc
Generated on
for Qt by
1.16.1