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