QML does not recognize ENUM returned by C++ Q_INVOKABLE function



  • QML

    console.log("model's category is " + converter.getModelCategory(currentIndex))
    

    C++

    Q_INVOKABLE Unit::Category getModelCategory(int index) { //TODO put in separate file
        qDebug() << "getModelCategory is called, Index is " << index;
        return qobject_cast<Unit *>(CategoryDataModel.at(index))->category();
    }
    

    error
    : Error: Unknown method return type: Unit::Category where Unit::Category is C++ enums and it is declared with Q_ENUM. However, Unit::Category is declared in other QOBJECT derived class, might it be a problem?
    How to solve this issue?



  • As far as I know, "Unit" type need to register throgh qmlRegisterType to make "Unit::Category" visible in QML.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.