aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/src/qmllint/unqualified.qdoc
blob: 7f2e315efed5c14cbfd66ed1320b1340aa6c44b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
\page qmllint-warnings-and-errors-unqualified.html
\ingroup qmllint-warnings-and-errors

\title Unqualified Access
\brief Accessing an outer scope without its id.

\section1 Unqualified Access

\section2 What happened?

A parent element was accessed without its \l{QML Object Attributes#the-id-attribute}{id}.

\section2 Why is this bad?

This makes the code harder to read and impedes performance.

\section2 Example

\qml
import QtQuick

Item {
    property int helloWorld
    Item {
        property int unqualifiedAccess: helloWorld + 1 // not ok: Unqualified access here.
    }
}
\endqml

You can fix this warning by referring to the parent object by
\l{QML Object Attributes#the-id-attribute}{id}.
If the object currently has no \l{QML Object Attributes#the-id-attribute}{id}, you will need to add
one first.

\qml
import QtQuick

Item {
    id: root
    property int helloWorld
    Item {
        property int unqualifiedAccess: root.helloWorld + 1 // ok: this access is qualified now!
    }
}
\endqml

\sa {QML Coding Conventions#unqualified-access}{QML Coding Conventions - Unqualified Access}
*/