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
restricted-type.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2023 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 Restricted type
8
\brief [restricted-type] A restricted type was accessed.
9
10
\qmllintwarningcategory restricted-type
11
12
\section1 You can't access an unscoped enum from here
13
14
\section2 What happened?
15
You accessed the value of an enum defined in C++ by its enum type name.
16
17
\section2 Why is this bad?
18
Unscoped enums defined in C++ can't be accessed by their enum type name.
19
They will be undefined at runtime.
20
21
\section2 Example
22
23
\qml
24
import QtQuick
25
import SomeModule // contains MyClass
26
27
Item {
28
property int i: MyClass.Hello.World
29
}
30
31
\endqml
32
where MyClass is defined as
33
\code
34
class MyClass: public QObject
35
{
36
Q_OBJECT
37
QML_ELEMENT
38
39
public:
40
enum Hello { World };
41
Q_ENUM(Hello);
42
...
43
44
};
45
\endcode
46
To fix this warning, remove the unnecessary enum type name from its QML usage:
47
\qml
48
import QtQuick
49
50
Item {
51
property int i: MyClass.World
52
}
53
54
\endqml
55
56
If you are the author of the enum, you can also modify the enum definition to use an enum
57
class instead of changing the QML code:
58
59
\code
60
class MyClass: public QObject
61
{
62
Q_OBJECT
63
QML_ELEMENT
64
65
public:
66
enum class Hello { World };
67
Q_ENUM(Hello);
68
...
69
};
70
\endcode
71
72
\note You can find more information about enum type registration
73
\l{qtqml-cppintegration-data.html#enumeration-types}{here}.
74
75
*/
qtdeclarative
src
qml
doc
src
qmllint
restricted-type.qdoc
Generated on
for Qt by
1.16.1