Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 Access
9\brief Accessing an outer scope without its id.
10
11\section1 Unqualified Access
12
13\section2 What happened?
14
15A parent element was accessed without its \l{QML Object Attributes#the-id-attribute}{id}.
16
17\section2 Why is this bad?
18
19This makes the code harder to read and impedes performance.
20
21\section2 Example
22
23\qml
24import QtQuick
25
26Item {
27 property int helloWorld
28 Item {
29 property int unqualifiedAccess: helloWorld + 1 // not ok: Unqualified access here.
30 }
31}
32\endqml
33
34You can fix this warning by referring to the parent object by
35\l{QML Object Attributes#the-id-attribute}{id}.
36If the object currently has no \l{QML Object Attributes#the-id-attribute}{id}, you will need to add
37one first.
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*/