In questa pagina

Impossibile accedere a un singleton come proprietà di un oggetto

Questa categoria di avvisi viene indicata da qmllint come " [access-singleton-via-object] ".

Accedere al singleton tramite l'oggetto

Cosa è successo?

Hai effettuato l'accesso a un singleton utilizzando la sintassi prevista per l'accesso alle proprietà associate da uno spazio dei nomi.

Perché è un errore?

Non è possibile accedere ai singleton in questo modo. L'espressione restituirà il valore "undefined".

Esempio

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
}

Per risolvere questo avviso, rimuovi " id " o "property" davanti al namespace se intendevi utilizzare il singleton. In alternativa, controlla che non ci siano errori di battitura se volevi accedere a una proprietà associata.

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.