Auf dieser Seite

Auf Singleton kann nicht als Eigenschaft eines Objekts zugegriffen werden

Diese Warnungskategorie wird von qmllint als „ [access-singleton-via-object] “ bezeichnet.

Zugriff auf Singleton über ein Objekt

Was ist passiert?

Sie haben auf ein Singleton mit der Syntax zugegriffen, die für den Zugriff auf angehängte Eigenschaften aus einem Namespace vorgesehen ist.

Warum ist das schlecht?

Auf Singletons kann auf diese Weise nicht zugegriffen werden. Der Ausdruck wird zu „undefined“ ausgewertet.

Beispiel

import QtQml
import QtQuick as QQ

QtObject {
    id: root
    // Cannot access singleton as a property of an object. Did you want to access an attached object?
    property var singletonAccess: root.QQ.Application.platform
}

Um diese Warnung zu beheben, entfernen Sie das „ id “ oder die Eigenschaft vor dem Namensraum, falls Sie das Singleton verwenden wollten. Alternativ sollten Sie auf Tippfehler prüfen, falls Sie auf eine angehängte Eigenschaft zugreifen wollten.

import QtQml
import QtQuick as QQ

QtObject {
    id: root
    property var singletonAccess: QQ.Application.platform
    property bool attachedPropertyAccess: root.QQ.ListView.isCurrentItem
}

© 2026 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.