如何从QML访问枚举?

时间:2016-04-13 11:43:18

标签: c++ qt enums

我有一个有枚举的课程

Q_PROPERTY(Heatercooler * heatercooler READ heatercooler CONSTANT USER true)

 class Heatercooler :  public HardwareComponent
    {
        Q_OBJECT
        Q_ENUMS(HeatTestState)

    public:
        Heatercooler(QObject *parent = 0);
         ~Heatercooler();

        void timerEvent(QTimerEvent *);

        enum HeatTestState
        {
            HEAT_IDLE = 0,
            HEAT_GO_AMBIENT_FOR_HOT,
            HEAT_GO_AMBIENT_FOR_COLD,
            HEAT_GO_AMBIENT_FOR_FINISH,
            HEAT_GO_HOT,
            HEAT_GO_COLD,
            HEAT_FINISH_SUCCESS,
            HEAT_FINISH_ERROR,

            HEAT_LT_COLD,
            HEAT_LT_COLD_Finished,   // lt cold is fifferent from normal cold -> #431
        };

public slots:
      void setState( HeatTestState newstate);

    }

我尝试从按钮访问它,但它表示枚举未定义

   Button {
                    text: qsTr("Heater")
                    priority: 1
                    Layout.fillWidth: true
                    onSecureClicked:  hardware.heatercooler.setState(HEAT_GO_AMBIENT_FOR_HOT)
                }

1 个答案:

答案 0 :(得分:0)

你的enum是在Heatercooler班里,所以你应该写Heatercooler::HEAT_GO_AMBIENT_FOR_HOT