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
17You accessed a parent element without its \l{QML Object Attributes#the-id-attribute}{id}.
18
19\section2 Why is this bad?
20
21This makes the code harder to read and impedes performance.
22
23\section2 Example
24
25\qml
26import QtQuick
27
28Item {
29 property int helloWorld
30 Item {
31 property int unqualifiedAccess: helloWorld + 1 // not ok: Unqualified access here.
32 }
33}
34\endqml
35To fix this warning, refer to the parent object by \l{QML Object Attributes#the-id-attribute}{id}.
36You will need to add an \l{QML Object Attributes#the-id-attribute}{id} first if the object
37currently has none.
38
39\qml
40import QtQuick
41
42Item {
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
57You accessed a type or context property that can't be found.
58
59\section2 Why is this bad?
60
61The QML tooling will not work on your types.
62
63\section2 Example
64
65\qml
66import QtQuick
67
68Item {
69 Component.onCompleted: { console.log(MyItem.someProperty); } // MyItem was not found
70}
71\endqml
72To 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?
90You 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.
92This 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
95actually installed and inside an \l{Import Statements#qml-import-path}{import path}.
96
97\section2 Why is this bad?
98Components with unknown attached property scopes or unknown grouped properties will not be created
99at runtime: they will be null instead.
100
101\section2 Example
102
103Let's try to use the (inexistent) attached property of \c Item or the (inexistent) grouped property
104\c grouped of \c Item:
105\qml
106import QtQuick
107
108Item {
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
114Indeed, \l{Item} does neither have any attached type nor any grouped property called \c{item}.
115To fix this warning, remove the attached type and the grouped property.
116
117Refer to \l{Attached Properties and Attached Signal Handlers} on how to use attached
118properties and to \l{QML Object Attributes#Grouped Properties}{Grouped Properties} on how to
119use grouped properties.
120
121\section1 No matching signal found for handler
122
123\section2 What happened?
124You used a \l{Signal and Handler Event System}{signal handler} on a signal that can't be found.
125This 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,
129for example.
130
131\note If you are importing QML modules with external dependencies, verify that they are
132actually installed and inside an \l{Import Statements#qml-import-path}{import path}.
133
134\section2 Why is this bad?
135Components with unknown signal handlers will not be created at runtime: they will be null
136instead.
137
138\section2 Example
139
140Lets try to write a signal handler for the (inexistent) signal \c{mySignal}:
141\qml
142import QtQuick
143
144Item {
145 onMySignal: console.log("hello") // not ok: no matching signal found for handler "onMySignal" [unqualified]
146}
147\endqml
148
149Indeed, this \l{Item} does not have any signal called \c{mySignal}. To fix this warning,
150remove the signal handler or add the missing signal.
151
152\section1 Implicitly defining signal handler in Connections is deprecated
153
154\section2 What happened?
155You used a signal handler on a \l[Qml]{Connections} type.
156
157\section2 Why is this bad?
158This is deprecated.
159
160\section2 Example
161
162\qml
163import QtQuick
164
165Window {
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
176To fix this warning, replace the signal handler binding with a function:
177
178\qml
179import QtQuick
180
181Window {
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*/