本页内容

未限定

qmllint 将此警告类别拼写为[unqualified] 。

未限定访问

发生了什么?

您在未指定ID 的情况下访问了父元素。

为什么这样不好?

这会降低代码的可读性并影响性能。

示例

import QtQuick

Item {
    property int helloWorld
    Item {
        property int unqualifiedAccess: helloWorld + 1 // not ok: Unqualified access here.
    }
}

要解决此警告,请通过ID 引用父对象。如果该对象目前没有 ID,则需要先为其添加一个ID。

import QtQuick

Item {
    id: root
    property int helloWorld
    Item {
        property int unqualifiedAccess: root.helloWorld + 1 // ok: this access is qualified now!
    }
}

未知关联/分组属性的作用域

发生了什么?

您使用了一个无法找到的附加属性类型或分组属性。这可能是由于拼写错误或缺少 QML 模块依赖项所致。

注意:如果您正在 导入带有外部依赖关系的 QML 模块,请确认这些模块已实际安装且位于导入路径内。

这有什么问题?

具有未知附加属性作用域或未知分组属性的组件在运行时将无法创建:它们将被视为 null。

示例

让我们尝试使用Item 的(不存在的)附加属性,或Item 的(不存在的)分组属性grouped :

import QtQuick

Item {
    Item.helloAttached: 44 // not ok: unknown attached property scope Item. [unqualified]
    grouped.helloGrouped: 44 // not ok: unknown grouped property scope grouped. [unqualified]
}

事实上,Item 既没有附着类型,也没有名为item 的分组属性。要解决此警告,请移除该附着类型和分组属性。

有关如何使用附加属性的信息,请参阅“附加属性与附加信号处理程序”;有关如何使用分组属性的信息,请参阅“分组属性”。

未找到与处理程序匹配的信号

发生了什么?

您在无法找到的信号上使用了信号处理程序。这可能是由于信号处理程序名称拼写错误,或者缺少 QML 模块依赖项所致。

注意: 信号处理程序的名称 由on 与大写信号名称拼接而成。例如,onHelloWorld 处理信号helloWorld ,而on_helloWorld 处理_helloWorld 。

注意:如果您正在 导入带有外部依赖项的 QML 模块,请确认这些依赖项已实际安装且位于导入路径内。

为什么这样做不好?

运行时不会创建具有未知信号处理程序的组件:它们将被视为 null。

示例

让我们尝试为(不存在的)信号mySignal 编写一个信号处理程序:

import QtQuick

Item {
    onMySignal: console.log("hello") // not ok: no matching signal found for handler "onMySignal" [unqualified]
}

事实上,这个Item 并没有名为mySignal 的信号。要解决此警告,请删除该信号处理程序或添加缺失的信号。

在 Connections 中隐式定义信号处理程序已被废弃

发生了什么?

您在Connections 类型上使用了信号处理程序。

为什么这样做不好?

此做法已弃用。

示例

import QtQuick

Window {
    id: root
    property int myInt

    Connections {
        target: root
        onMyIntChanged: console.log("new int", myInt)
    }
}

要解决此警告,请将信号处理程序绑定替换为一个函数:

import QtQuick

Window {
    id: root
    property int myInt

    Connections {
        target: root
        function onMyIntChanged() { console.log("new int", myInt) }
    }
}

另请参阅 《QML 编码规范》——未限定访问。

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