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