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