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