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