本页内容

无法创建的类型

qmllint 将此警告类别拼写为[uncreatable-type] 。

命名空间必须以大写字母开头

发生了什么?

您使用了来自小写命名空间的 QML 对象。

为什么这样不好?

QML 语言禁止使用小写命名空间。

示例

import QtQuick as quick

quick.Item { ... }

要消除此警告,请将命名空间重命名为以大写字母开头:

import QtQuick as Quick

Quick.Item { ... }

无法创建单例类型

发生了什么?

您尝试从单例类型实例化一个 QML 对象。

为什么这样不好?

QML 语言禁止对单例进行实例化。

示例

import QtQuick

Item {
    Qt { // note: Qt is a singleton type
        id: qt
    }

    property string someProperty: qt.uiLanguage
}

要消除此警告,请直接使用单例,而无需对其进行实例化:

import QtQuick

Item {
    property string someProperty: Qt.uiLanguage
}

类型无法创建

发生了什么?

您尝试从uncreatable type 中实例化一个QML对象。

为什么这样不好?

不可创建的类型已被特别标记,以禁止对其进行实例化。您可能误用了本应仅作为附加类型或接口使用的类型。

示例

附加类型的误用

import QtQuick

Item {
    Keys {
        onPressed: function (key) { ... }
    }
}

要消除此警告,请使用Keys 附着类型,而不是对其进行实例化:

import QtQuick

Item {
    Keys.onPressed: function (key) { ... }
}

接口滥用

import QtQuick

Item {
    property PointerHandler myHandler: PointerHandler {}
}

要解决此警告,请使用更具体的派生类型,例如 `TapHandler`:

import QtQuick

Item {
    property PointerHandler myHandler: TapHandler {}
}

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