1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5\page qmllint-warnings-and-errors-non-list-property.html
6\ingroup qmllint-warnings-and-errors
8\title Non-List Property
9\brief Multiple values were assigned to a non-list property.
11\section1 Cannot Assign Multiple Objects To A Default Non-List Property
13\section2 What happened?
14A \l{Default Properties}{default property} has multiple bindings but the default
15property type is not a list type and only expects one binding.
17\section2 Why is this bad?
18All the bindings to the default property, except the last one, will be ignored. This most likely
19hints that the default property should instead be a list, or that there are too many bindings to
24Let's declare a component \c{MyComponent} that has one default non-list property, and then lets
25bind three items to that default property:
30 component MyComponent: QtObject {
31 default property Item helloWorld
34 // first item bound to default property:
35 Item { objectName: "first" } // will warn: Cannot assign multiple objects to a default non-list property [non-list-property]
36 // second item bound to default property:
37 Item { objectName: "second" } // not ok: default property was bound already
38 // third item bound to default property:
39 Item { objectName: "third" } // not ok: default property was bound already
41 Component.onCompleted: console.log(helloWorld.objectName) // prints "third"
46You can fix this warning by replacing the default property by a list:
51 component MyComponent: QtObject {
52 default property list<Item> helloWorld
55 // first item bound to default property:
56 Item { objectName: "first" } // ok: binding a first item to the list
57 // second item bound to default property:
58 Item { objectName: "second" } // ok: binding a second item to the list
59 // third item bound to default property:
60 Item { objectName: "third" } // ok: binding a third item to the list
64You can also fix this warning by removing all the unwanted bindings, in case the default property
65is not supposed to be a list:
70 component MyComponent: QtObject {
71 default property Item helloWorld
74 Item { objectName: "first" } // ok: just one item bound to default property
77 Item { objectName: "second" } // ok: just one item bound to default property
80 Item { objectName: "third" } // ok: just one item bound to default property