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