不能访问作为对象属性的单例
此警告类别由 qmllint 拼写为[access-singleton-via-object] 。
通过对象访问单例
发生了什么?
您使用从命名空间访问附加属性的语法访问了单例。
为什么这样做不好?
单例不能以这种方式访问。表达式的值将是未定义的。
示例
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 或属性。或者,如果你想访问附加属性,检查是否有错别字。
© 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.