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{QML Object Attributes#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{QML Object Attributes#Grouped Properties}{Grouped Properties} on how to
85use grouped properties.
86
87\section1 No matching signal found for handler
88
89\section2 What happened?
90You used a \l{Signal and Handler Event System}{signal handler} on a signal that can't be found.
91This 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,
95for example.
96
97\note If you are importing QML modules with external dependencies, verify that they are
98actually installed and inside an \l{Import Statements#qml-import-path}{import path}.
99
100\section2 Why is this bad?
101Components with unknown signal handlers will not be created at runtime: they will be null
102instead.
103
104\section2 Example
105
106Lets try to write a signal handler for the (inexistent) signal \c{mySignal}:
107\qml
108import QtQuick
109
110Item {
111 onMySignal: console.log("hello") // not ok: no matching signal found for handler "onMySignal" [unqualified]
112}
113\endqml
114
115Indeed, this \l{Item} does not have any signal called \c{mySignal}. To fix this warning,
116remove the signal handler or add the missing signal.
117
118\section1 Implicitly defining signal handler in Connections is deprecated
119
120\section2 What happened?
121You used a signal handler on a \l[Qml]{Connections} type.
122
123\section2 Why is this bad?
124This is deprecated.
125
126\section2 Example
127
128\qml
129import QtQuick
130
131Window {
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
142To fix this warning, replace the signal handler binding with a function:
143
144\qml
145import QtQuick
146
147Window {
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*/