Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Solved Error returning enum type

    General and Desktop
    error
    2
    7
    1511
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • yuvaram
      yuvaram last edited by

      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.

      Yuvaram Aligeti
      Embedded Qt Developer
      : )

      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by Chris Kawa

        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.

        yuvaram 1 Reply Last reply Reply Quote 0
        • yuvaram
          yuvaram @Chris Kawa last edited by

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

          Yuvaram Aligeti
          Embedded Qt Developer
          : )

          1 Reply Last reply Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by

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

            yuvaram 1 Reply Last reply Reply Quote 0
            • yuvaram
              yuvaram @Chris Kawa last edited by

              @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(){
              ^

              Yuvaram Aligeti
              Embedded Qt Developer
              : )

              1 Reply Last reply Reply Quote 0
              • Chris Kawa
                Chris Kawa Moderators last edited by

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

                myclass::E_Priority myclass::getpriorityFunc() const {
                ...
                
                yuvaram 1 Reply Last reply Reply Quote 2
                • yuvaram
                  yuvaram @Chris Kawa last edited by

                  @Chris-Kawa
                  Thank you :)

                  Yuvaram Aligeti
                  Embedded Qt Developer
                  : )

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post