本页内容

ID引用

qmllint 将此警告类别拼写为[syntax.id-quotation] 。

ID 不需要引号

发生了什么?

您将ID用引号包住了。

为什么这样不好?

这可能会导致 ID 与字符串之间产生混淆。QML 语言不要求 ID 使用引号,并且禁止将更复杂的字符串表达式用作 ID。

示例

import QtQuick

Item {
    id: "root"
}

要解决此警告,请删除引号:

import QtQuick

Item {
    id: root
}

© 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.