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
alias-cycle.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\ingroup qmllint-warnings-and-errors
6
7\title Alias cycle
8\brief [alias-cycle] Alias property is part of an alias cycle.
9
10\qmllintwarningcategory alias-cycle
11
12\section1 Alias property is part of an alias cycle
13
14\section2 What happened?
15A \l{QML Object Attributes#property-aliases}{property alias} resolves to itself or to another
16alias resolving to itself.
17
18Usually, \l{QML Object Attributes#property-aliases}{a property alias} should reference another
19property either directly, or indirectly by passing through another alias property.
20
21If a property alias directly or indirectly references itself, then it forms an alias cycle.
22The warning indicates that the current alias property is inside or references
23an alias cycle, see \l{#example}{Example}.
24
25\section2 Why is this bad?
26Instances of components with alias cycles will not be created at runtime: they will be null instead.
27
28\section2 Example
29\qml
30import QtQuick
31
32Item {
33 id: someId
34 property alias myself: someId.myself // not ok: referring to itself
35
36 property alias cycle: someId.cycle2 // not ok: indirectly referring to itself
37 property alias cycle2: someId.cycle
38
39 property alias indirect: someId.cycle // not ok: referring to alias indirectly referring to itself
40}
41\endqml
42To fix this warning, break up the alias cycles:
43\qml
44import QtQuick
45
46Item {
47 id: someId
48 Item {
49 id: anotherId
50 property string myself
51 property int cycle
52 }
53 property alias myself: anotherId.myself // ok: referring to a property
54
55 property alias cycle: someId.cycle2 // ok: does not refer to itself anymore
56 property alias cycle2: anotherId.cycle // ok: not a cycle anymore
57
58 property alias indirect: someId.cycle // ok: cycle does not form an alias cycle anymore
59}
60\endqml
61*/