How to access C++ enum from QML?

后端 未结 7 659
清歌不尽
清歌不尽 2020-12-04 18:03
class StyleClass : public QObject {
public:
    typedef enum
        {
            STYLE_RADIAL,
            STYLE_ENVELOPE,
            STYLE_FILLED
        }  Styl         


        
7条回答
  •  执念已碎
    2020-12-04 18:13

    Additional information (not documented prior to Qt 5.5):

    Your enum value names must start with a Capital letter.

    This will work:

    enum EnStyle
    {
        STYLE_RADIAL,
        STYLE_ENVELOPE,
        STYLE_FILLED
    };
    Q_ENUMS(EnStyle)
    

    This does not:

    enum EnStyle
    {
        styleRADIAL,
        styleENVELOPE,
        styleFILLED
    };
    Q_ENUMS(EnStyle)
    

    You won't get any kind of error at compile time, they are just ignored by the QML engine.

提交回复
热议问题