无法创建的类型

此警告类别由 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 {}
}

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