只读属性
此警告类别由 qmllint 拼写[read-only-property]
。
无法为只读属性赋值
发生了什么?
写入了一个只读属性。
为什么会这样?
当 QML 引擎看到写入只读属性时,会抛出 Type Error(类型错误)。
示例
import QtQuick Item { id: root readonly property int someNumber: 10 Component.onCompleted: { someNumber = 20 // not ok: TypeError: Cannot assign to read-only property } }
要修复此警告,请移除对只读属性的写入,写入另一个非只读属性,或者移除只读修饰符(如果你是属性定义的作者)。
另请参阅 " 只读属性"。
© 2025 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.