QML + QEnums



  • Greetings Qt community,

    I'm calling this function from QML:
    @Q_INVOKABLE OtherClass::Type Class::getType() const;@
    In the QML:
    @property int type: -1

    type = class.getType();@
    I get the following message:
    @'Cannot assign [undefined] to int'@

    The enum is declared with Q_ENUM in the OtherClass. And I declared OtherClass with qmlRegisterType.

    Am I missing something ?

    Thanks.



  • Hello,

    I don't think it's possible to do that (your syntax seems ok)
    I have tried it a time ago, but i finally cast the value int for using it in QML side.



  • Hi,

    I ended up doing the same as dmcr... It seems that Q_ENUMS work correctly in QML for comparisons, assignment and as function arguments but don't work when passed from C++ as either function return values or signal arguments.



  • Hi SteveKing,

    That sounds like a bug. Can you confirm that it's still the case in QtQuick2? If so, please file a bug report.

    Cheers,
    Chris.

    /edit: I should add - there is some special considerations with enums (and the QMetaObject extension stuff) which I'm not too familiar, so perhaps the fact that the source of the type information is a separate QMetaObject, is the issue in this particular case. I don't know. Either way, it should work - whether or not it's technically feasible to fix is another question...



  • Hi Chris,

    I'm not using Qt5 (QtQuick2) yet so I don't know if it's there. I think this might be related to existing bugs: "15983":https://bugreports.qt-project.org/browse/QTBUG-15983 and "27041":https://bugreports.qt-project.org/browse/QTBUG-27041

    Regards,
    Steve


Log in to reply
 

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