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
uncreatable-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 Uncreatable type
8
\brief [uncreatable-type] Types that can't be created.
9
10
\qmllintwarningcategory uncreatable-type
11
12
\section1 Namespace must start with an upper case letter
13
14
\section2 What happened?
15
You used a QML object from a lower-case namespace.
16
17
\section2 Why is this bad?
18
The QML language forbids lower-case namespaces.
19
20
\section2 Example
21
\qml
22
import QtQuick as quick
23
24
quick.Item { ... }
25
26
\endqml
27
To fix the warning, rename the namespace to start with a capital letter:
28
\qml
29
import QtQuick as Quick
30
31
Quick.Item { ... }
32
33
\endqml
34
35
\section1 Singleton type is not creatable
36
37
\section2 What happened?
38
You tried to instantiate a QML object from a \l{qml-singleton.html}{singleton type}.
39
40
\section2 Why is this bad?
41
The QML language forbids instantiations of singletons.
42
43
\section2 Example
44
\qml
45
import QtQuick
46
47
Item {
48
Qt { // note: Qt is a singleton type
49
id: qt
50
}
51
52
property string someProperty: qt.uiLanguage
53
}
54
55
\endqml
56
To fix the warning, use the singleton directly without instantiating it:
57
\qml
58
import QtQuick
59
60
Item {
61
property string someProperty: Qt.uiLanguage
62
}
63
64
\endqml
65
66
\section1 Type is not creatable
67
68
\section2 What happened?
69
You tried to instantiate a QML object from an
70
\l{QML_UNCREATABLE}{uncreatable type}.
71
72
\section2 Why is this bad?
73
Uncreatable types are specifically marked to forbid instantiations.
74
You might be misusing a type that should only be used as an attached type or
75
as an interface.
76
77
\section2 Example
78
79
\section3 Attached type misuse
80
\qml
81
import QtQuick
82
83
Item {
84
Keys {
85
onPressed: function (key) { ... }
86
}
87
}
88
89
\endqml
90
To fix the warning, use the \c Keys attached type instead of instantiating it:
91
\qml
92
import QtQuick
93
94
Item {
95
Keys.onPressed: function (key) { ... }
96
}
97
98
\endqml
99
100
\section3 Interface misuse
101
\qml
102
import QtQuick
103
104
Item {
105
property PointerHandler myHandler: PointerHandler {}
106
}
107
108
\endqml
109
To fix the warning, use a more specific derived type like \c TapHandler:
110
\qml
111
import QtQuick
112
113
Item {
114
property PointerHandler myHandler: TapHandler {}
115
}
116
117
\endqml
118
119
*/
qtdeclarative
src
qml
doc
src
qmllint
uncreatable-type.qdoc
Generated on
for Qt by
1.16.1