Restricted type

This warning category is spelled c{[restricted-type]} by qmllint.

You can't access an unscoped enum from here

What happened?

You accessed the value of an enum defined in C++ by its enum type name.

Why is this bad?

Unscoped enums defined in C++ can't be accessed by their enum type name. They will be undefined at runtime.

Example

import QtQuick
import SomeModule // contains MyClass

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

where MyClass is defined as

class MyClass: public QObject
{
    Q_OBJECT
    QML_ELEMENT

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

};

To fix this warning, remove the unnecessary enum type name from its QML usage:

import QtQuick

Item {
    property int i: MyClass.World
}

If you are the author of the enum, you can also modify the enum definition to use an enum class instead of changing the QML code:

class MyClass: public QObject
{
    Q_OBJECT
    QML_ELEMENT

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

Note: You can find more information about enum type registration here.

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