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
unqualified.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-unqualified.html
6
\ingroup qmllint-warnings-and-errors
7
8
\title Unqualified
9
\brief [unqualified] Accessing an outer scope without its id.
10
11
\qmllintwarningcategory unqualified
12
13
\section1 Unqualified access
14
15
\section2 What happened?
16
17
You accessed a parent element without its \l{QML Object Attributes#the-id-attribute}{id}.
18
19
\section2 Why is this bad?
20
21
This makes the code harder to read and impedes performance.
22
23
\section2 Example
24
25
\qml
26
import QtQuick
27
28
Item {
29
property int helloWorld
30
Item {
31
property int unqualifiedAccess: helloWorld + 1 // not ok: Unqualified access here.
32
}
33
}
34
\endqml
35
To fix this warning, refer to the parent object by \l{QML Object Attributes#the-id-attribute}{id}.
36
You will need to add an \l{QML Object Attributes#the-id-attribute}{id} first if the object
37
currently has none.
38
39
\qml
40
import QtQuick
41
42
Item {
43
id: root
44
property int helloWorld
45
Item {
46
property int unqualifiedAccess: root.helloWorld + 1 // ok: this access is qualified now!
47
}
48
}
49
\endqml
50
51
\sa {QML Coding Conventions#unqualified-access}{QML Coding Conventions - Unqualified Access}
52
53
\section1 Type was not found
54
55
\section2 What happened?
56
57
You accessed a type or context property that can't be found.
58
59
\section2 Why is this bad?
60
61
The QML tooling will not work on your types.
62
63
\section2 Example
64
65
\qml
66
import QtQuick
67
68
Item {
69
Component.onCompleted: { console.log(MyItem.someProperty); } // MyItem was not found
70
}
71
\endqml
72
To fix this warning,
73
\list
74
\li Ensure that the QML Module of MyItem is built.
75
\li Ensure that the QML Module of MyItem is imported.
76
\li Ensure that MyItem is correctly spelled.
77
\li Ensure that MyItem is registered via \l{Registering C++ Types with the QML Type System} as
78
\list
79
\li A singleton type.
80
\li An attached type.
81
\li A namespace type with enums.
82
\endlist
83
\li Ensure that MyItem is not a context property, see \l{Context properties} on how to replace
84
context properties.
85
\endlist
86
87
\section1 Unknown attached/grouped property scope
88
89
\section2 What happened?
90
You used an \l{Attached Properties and Attached Signal Handlers}{attached property} type or
91
\l{QML Object Attributes#Grouped Properties}{grouped property} that can't be found.
92
This can be caused by a typo or by a missing QML module dependency.
93
94
\note If you are importing QML modules with external dependencies, verify that they are
95
actually installed and inside an \l{Import Statements#qml-import-path}{import path}.
96
97
\section2 Why is this bad?
98
Components with unknown attached property scopes or unknown grouped properties will not be created
99
at runtime: they will be null instead.
100
101
\section2 Example
102
103
Let's try to use the (inexistent) attached property of \c Item or the (inexistent) grouped property
104
\c grouped of \c Item:
105
\qml
106
import QtQuick
107
108
Item {
109
Item.helloAttached: 44 // not ok: unknown attached property scope Item. [unqualified]
110
grouped.helloGrouped: 44 // not ok: unknown grouped property scope grouped. [unqualified]
111
}
112
\endqml
113
114
Indeed, \l{Item} does neither have any attached type nor any grouped property called \c{item}.
115
To fix this warning, remove the attached type and the grouped property.
116
117
Refer to \l{Attached Properties and Attached Signal Handlers} on how to use attached
118
properties and to \l{QML Object Attributes#Grouped Properties}{Grouped Properties} on how to
119
use grouped properties.
120
121
\section1 No matching signal found for handler
122
123
\section2 What happened?
124
You used a \l{Signal and Handler Event System}{signal handler} on a signal that can't be found.
125
This can be caused by a typo in the signal handler or by a missing QML module dependency.
126
127
\note The name of a signal handler is \c on concatenated with the capitalized signal name.
128
\c onHelloWorld handles the signal \c helloWorld and \c on_helloWorld handles \c _helloWorld,
129
for example.
130
131
\note If you are importing QML modules with external dependencies, verify that they are
132
actually installed and inside an \l{Import Statements#qml-import-path}{import path}.
133
134
\section2 Why is this bad?
135
Components with unknown signal handlers will not be created at runtime: they will be null
136
instead.
137
138
\section2 Example
139
140
Lets try to write a signal handler for the (inexistent) signal \c{mySignal}:
141
\qml
142
import QtQuick
143
144
Item {
145
onMySignal: console.log("hello") // not ok: no matching signal found for handler "onMySignal" [unqualified]
146
}
147
\endqml
148
149
Indeed, this \l{Item} does not have any signal called \c{mySignal}. To fix this warning,
150
remove the signal handler or add the missing signal.
151
152
\section1 Implicitly defining signal handler in Connections is deprecated
153
154
\section2 What happened?
155
You used a signal handler on a \l[Qml]{Connections} type.
156
157
\section2 Why is this bad?
158
This is deprecated.
159
160
\section2 Example
161
162
\qml
163
import QtQuick
164
165
Window {
166
id: root
167
property int myInt
168
169
Connections {
170
target: root
171
onMyIntChanged: console.log("new int", myInt)
172
}
173
}
174
\endqml
175
176
To fix this warning, replace the signal handler binding with a function:
177
178
\qml
179
import QtQuick
180
181
Window {
182
id: root
183
property int myInt
184
185
Connections {
186
target: root
187
function onMyIntChanged() { console.log("new int", myInt) }
188
}
189
}
190
\endqml
191
*/
qtdeclarative
src
qml
doc
src
qmllint
unqualified.qdoc
Generated on
for Qt by
1.16.1