Qt World Summit: Submit your Presentation

QML autocomplete / intellisense doesn't work for namespace enums

  • Hi all. Running Qt Creator 4.14.0 with a Qt 6.0.1 MSVC 2019 x64 toolchain.

    I have a namespace containing multiple enums which I want to be accesible to my QML. This is easy enough as the following example demonstrates:

    // testnamespace.h
    namespace TestNamespace
        enum class TestEnum {
    // main.cpp
    int main(int argc, char *argv[])
        qmlRegisterUncreatableMetaObject(TestNamespace::staticMetaObject, "My.Company", 1, 0, "TestNamespace",  "Error: namespace not creatable");
    // main.qml
    import QtQuick 2.15
    import QtQuick.Window 2.15
    import My.Company 1.0
    Window {
        width: 640
        height: 480
        visible: true
        title: TestNamespace.TestEnum_option3

    The problem is that while it will autocomplete the namespace in the QML file, there is no autocomplete for any of the namespace enum values.

    If instead the enum is placed into a QObject derived class and the class type is registered in the same way using qmlRegisterType() then the QML editor provides autocomplete for the enum values, but I don't really see this as a good solution for a number of reasons.

    So I guess the question is, is there any intent to resolve this in the future? Or is there a workaround that anyone knows of that can be used to get the autocomplete working for the namespace enum values?

  • Moderators

    enums in a Q_NAMESPACE type should rather be registered with Q_ENUM_NS

  • In the above example using Q_ENUM_NS yeilds no change for me and there is still no intellisense / autocomplete in the QML editor for the enum values.

  • Moderators

    @aatwo I have my QML enums in a basic c++ class with Q_GADGET macro as a lightweight alternative to Q_OBJECT (it does not require the class to be derived from QObject, too)

    If thats an alternative for you?

Log in to reply