Nicht-Listen-Eigenschaft

Diese Warnkategorie wird von qmllint mit [non-list-property] angegeben.

Es können nicht mehrere Objekte einer Standard-Nicht-Listen-Eigenschaft zugewiesen werden

Was ist passiert?

Eine Standardeigenschaft hat mehrere Bindungen, aber der Typ der Standardeigenschaft ist kein Listentyp und erwartet nur eine Bindung.

Warum ist das schlecht?

Alle Bindungen an die Standardeigenschaft, außer der letzten, werden ignoriert. Dies deutet höchstwahrscheinlich darauf hin, dass die Standardeigenschaft stattdessen eine Liste sein sollte oder dass es zu viele Bindungen für dieselbe Eigenschaft gibt.

Beispiel

Deklarieren wir eine Komponente MyComponent, die eine Standardeigenschaft hat, die keine Liste ist, und binden wir dann drei Elemente an diese Standardeigenschaft:

import QtQuick

Item {
    component MyComponent: QtObject {
        default property Item helloWorld
    }
    MyComponent {
        // first item bound to default property:
        Item { objectName: "first" } // will warn: Cannot assign multiple objects to a default non-list property [non-list-property]
        // second item bound to default property:
        Item { objectName: "second" } // not ok: default property was bound already
        // third item bound to default property:
        Item { objectName: "third" } // not ok: default property was bound already

        Component.onCompleted: console.log(helloWorld.objectName) // prints "third"
    }
}

Um diese Warnung zu beheben, ersetzen Sie die Standardeigenschaft durch eine Liste:

import QtQuick

Item {
    component MyComponent: QtObject {
        default property list<Item> helloWorld
    }
    MyComponent {
        // first item bound to default property:
        Item { objectName: "first" } // ok: binding a first item to the list
        // second item bound to default property:
        Item { objectName: "second" } // ok: binding a second item to the list
        // third item bound to default property:
        Item { objectName: "third" } // ok: binding a third item to the list
    }
}

Um diese Warnung zu beheben, entfernen Sie alle unerwünschten Bindungen, falls die Standardeigenschaft keine Liste sein soll:

import QtQuick

Item {
    component MyComponent: QtObject {
        default property Item helloWorld
    }
    MyComponent {
        Item { objectName: "first" } // ok: just one item bound to default property
    }
    MyComponent {
        Item { objectName: "second" } // ok: just one item bound to default property
    }
    MyComponent {
        Item { objectName: "third" } // ok: just one item bound to default property
    }
}

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.