このページについて

制限付き型

この警告カテゴリは、qmllint では「[restricted-type] 」と表記されます。

ここからスコープ外列挙型にアクセスできません

何が起きたのですか?

C++で定義された列挙型の値に、その列挙型名を使ってアクセスしました。

なぜ問題なのか?

C++ で定義されたスコープのない列挙型は、その列挙型名ではアクセスできません。実行時には未定義となります。

例

import QtQuick
import SomeModule // contains MyClass

Item {
    property int i: MyClass.Hello.World
}

ここで、MyClass は次のように定義されています。

class MyClass: public QObject
{
    Q_OBJECT
    QML_ELEMENT

public:
    enum Hello { World };
    Q_ENUM(Hello);
    ...

};

この警告を解消するには、QMLでの使用箇所から不要な列挙型名を削除してください:

import QtQuick

Item {
    property int i: MyClass.World
}

列挙型の作者である場合は、QML コードを変更する代わりに、列挙型の定義を修正して enum class を使用することもできます:

class MyClass: public QObject
{
    Q_OBJECT
    QML_ELEMENT

public:
    enum class Hello { World };
    Q_ENUM(Hello);
    ...
};

注: 列挙型登録に関する詳細はこちらをご覧ください 。

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