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