Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Restricted type

This warning category is spelled [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.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded