不合格

此警告类别由 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 模块有外部依赖关系,请确认它们已安装并在导入路径内。

为什么会这样?

未知附加属性作用域或未知分组属性的组件不会在运行时创建:它们将是空的。

示例

让我们尝试使用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 模块,请确认它们已安装并在导入路径内。

为什么这样做不好?

运行时将不会创建未知信号处理器的组件:它们将是空的。

示例

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

import QtQuick

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

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

在连接中隐含定义信号处理程序已被弃用

发生了什么?

您在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 Coding Conventions - Unqualified Access

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