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 Unknown attached/grouped property scope
54
55
\section2 What happened?
56
You used an \l{Attached Properties and Attached Signal Handlers}{attached property} type or
57
\l{QML Object Attributes#Grouped Properties}{grouped property} that can't be found.
58
This can be caused by a typo or by a missing QML module dependency.
59
60
\note If you are importing QML modules with external dependencies, verify that they are
61
actually installed and inside an \l{Import Statements#qml-import-path}{import path}.
62
63
\section2 Why is this bad?
64
Components with unknown attached property scopes or unknown grouped properties will not be created
65
at runtime: they will be null instead.
66
67
\section2 Example
68
69
Let's try to use the (inexistent) attached property of \c Item or the (inexistent) grouped property
70
\c grouped of \c Item:
71
\qml
72
import QtQuick
73
74
Item {
75
Item.helloAttached: 44 // not ok: unknown attached property scope Item. [unqualified]
76
grouped.helloGrouped: 44 // not ok: unknown grouped property scope grouped. [unqualified]
77
}
78
\endqml
79
80
Indeed, \l{Item} does neither have any attached type nor any grouped property called \c{item}.
81
To fix this warning, remove the attached type and the grouped property.
82
83
Refer to \l{Attached Properties and Attached Signal Handlers} on how to use attached
84
properties and to \l{QML Object Attributes#Grouped Properties}{Grouped Properties} on how to
85
use grouped properties.
86
87
\section1 No matching signal found for handler
88
89
\section2 What happened?
90
You used a \l{Signal and Handler Event System}{signal handler} on a signal that can't be found.
91
This can be caused by a typo in the signal handler or by a missing QML module dependency.
92
93
\note The name of a signal handler is \c on concatenated with the capitalized signal name.
94
\c onHelloWorld handles the signal \c helloWorld and \c on_helloWorld handles \c _helloWorld,
95
for example.
96
97
\note If you are importing QML modules with external dependencies, verify that they are
98
actually installed and inside an \l{Import Statements#qml-import-path}{import path}.
99
100
\section2 Why is this bad?
101
Components with unknown signal handlers will not be created at runtime: they will be null
102
instead.
103
104
\section2 Example
105
106
Lets try to write a signal handler for the (inexistent) signal \c{mySignal}:
107
\qml
108
import QtQuick
109
110
Item {
111
onMySignal: console.log("hello") // not ok: no matching signal found for handler "onMySignal" [unqualified]
112
}
113
\endqml
114
115
Indeed, this \l{Item} does not have any signal called \c{mySignal}. To fix this warning,
116
remove the signal handler or add the missing signal.
117
118
\section1 Implicitly defining signal handler in Connections is deprecated
119
120
\section2 What happened?
121
You used a signal handler on a \l[Qml]{Connections} type.
122
123
\section2 Why is this bad?
124
This is deprecated.
125
126
\section2 Example
127
128
\qml
129
import QtQuick
130
131
Window {
132
id: root
133
property int myInt
134
135
Connections {
136
target: root
137
onMyIntChanged: console.log("new int", myInt)
138
}
139
}
140
\endqml
141
142
To fix this warning, replace the signal handler binding with a function:
143
144
\qml
145
import QtQuick
146
147
Window {
148
id: root
149
property int myInt
150
151
Connections {
152
target: root
153
function onMyIntChanged() { console.log("new int", myInt) }
154
}
155
}
156
\endqml
157
*/
qtdeclarative
src
qml
doc
src
qmllint
unqualified.qdoc
Generated on
for Qt by
1.16.1