Error returning enum type



  • Hi,

    class myclass : public QObject
    {
    Q_OBJECT
    Q_ENUMS(E_Priority)
    Q_PROPERTY(E_Priority priorityFunc READ getpriorityFunc WRITE setpriorityFunc NOTIFY SIGpriorityChanged)
    public:
    enum E_Priority { High, Low, VeryHigh, VeryLow };
    explicit myclass(QObject *parent = 0);
    E_Priority getpriorityFunc()const;
    void setpriorityFunc(E_Priority prpt);

    signals:
    void SIGpriorityChanged(E_Priority);

    public slots:
    private:
    E_Priority m_priority;
    };

    myclass::myclass(QObject *parent) : QObject(parent)
    {
    qDebug()<<Q_FUNC_INFO<<endl;
    }

    E_Priority myclass:: getpriorityFunc(){
    qDebug()<<Q_FUNC_INFO<<endl;
    return m_priority;
    }

    void myclass:: setpriorityFunc(E_Priority prpt){
    qDebug()<<Q_FUNC_INFO<<endl;
    m_priority = prpt;
    emit SIGpriorityChanged(m_priority);
    }

    There is a error : 'E_Priority' does not name type.


  • Moderators

    E_Priority is not known in the global scope, thus when declaring a function that returns it you should scope it to the class it is declared in:

    myclass::E_Priority myclass::getpriorityFunc(){
    ...
    

    Btw. please surround your code with ```. It makes it a lot easier to read.



  • @Chris-Kawa
    Thank you.
    But there is Prototype miss match error


  • Moderators

    That doesn't tell much. Can you post the full error and the code that generates it?



  • @Chris-Kawa
    Code is already share in above post.

    myclass.cpp:8: error: prototype for 'myclass::E_Priority myclass::getpriorityFunc()' does not match any in class 'myclass'
    myclass::E_Priority myclass:: getpriorityFunc(){
    ^


  • Moderators

    Ok, your function is declared const in the header but non-const in the definition. Should be:

    myclass::E_Priority myclass::getpriorityFunc() const {
    ...
    


  • @Chris-Kawa
    Thank you :)


Log in to reply
 

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