Sur cette page

Impossible d'accéder à un singleton en tant que propriété d'un objet

Cette catégorie d'avertissement est orthographiée [access-singleton-via-object] par qmllint.

Accès au singleton via un objet

Qu'est-ce qui s'est passé ?

Vous avez accédé à un singleton en utilisant la syntaxe d'accès aux propriétés attachées d'un espace de noms.

Pourquoi est-ce mauvais ?

Les singletons ne peuvent pas être accédés de cette manière. L'expression sera évaluée à undefined.

Exemple

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
}

Pour corriger cet avertissement, supprimez id ou property devant l'espace de noms si vous avez l'intention d'utiliser le singleton. Sinon, vérifiez les fautes de frappe si vous vouliez accéder à une propriété attachée.

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.