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
non-root-enum.qdoc
Go to the documentation of this file.
1// Copyright (C) 2025 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 Enum declared outside the root element
8\brief [non-root-enum] An enum was declared outside the root element.
9
10\qmllintwarningcategory non-root-enum
11
12\section1 Enum declared outside the root element
13
14\section2 What happened?
15An enum was declared outside of the root element of the component.
16
17\section2 Why is that bad?
18It won't be accessible. Enums are accessed as
19<component name>.<optional enum name>.<enum entry>. If the enum is not at the
20root of the component, this lookup won't work.
21
22\section2 Example
23\qml
24// Main.qml
25import QtQuick
26
27Item {
28 Item {
29 id: item
30 enum Color { Red, Green, Blue }
31 }
32}
33\endqml
34To fix this warning, move the enum to the root of the component:
35\qml
36// Main.qml
37import QtQuick
38
39Item {
40 enum Color { Red, Green, Blue } // Accessible in Main.qml but also from other files
41 Item {
42 id: item
43 }
44}
45\endqml
46*/