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