このページでは

シングルトンをオブジェクトのプロパティとしてアクセスできません

この警告カテゴリは、qmllint によって「[access-singleton-via-object] 」と表記されます。

オブジェクトを介してシングルトンにアクセスする

何が起きたのか?

名前空間からアタッチドプロパティにアクセスするための構文を使用して、シングルトンにアクセスしました。

なぜ問題なのか?

シングルトンにはこの方法でアクセスすることはできません。この式は undefined と評価されます。

例

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
}

この警告を解消するには、シングルトンを使用するつもりだった場合は、名前空間の前にある `id ` または `property` を削除してください。あるいは、アタッチドプロパティにアクセスしようとしていた場合は、入力ミスがないか確認してください。

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.