Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Changing class local enum to enum class
Forum Updated to NodeBB v4.3 + New Features

Changing class local enum to enum class

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 555 Views 3 Watching
  • 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by Perdrix
    #1

    I have a class:

    class QLinearGradientCtrl : public QWidget
    {
    	Q_OBJECT
    	Q_PROPERTY(QLinearGradient gradient READ gradient WRITE setGradient)
    	Q_PROPERTY(int gradientWidth READ orientation WRITE setGradientWidth)
    	Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation)
    
    public:
    	enum Orientation
    	{
    		ForceHorizontal,
    		ForceVertical,
    		Auto
    	};
    

    I changed the enum to enum class Orientation, but that gave me:

    moc_QLinearGradientCtrl.cpp
    1>C:\Users\amonra\Documents\GitHub\DSS\DeepSkyStacker\GeneratedFiles\moc_QLinearGradientCtrl.cpp(199,65): error C2440: '=': cannot convert from 'QLinearGradientCtrl::Orientation' to 'int'
    

    What do I need to do to get this working?

    Chris KawaC 1 Reply Last reply
    0
    • JonBJ JonB

      @Perdrix
      I know nothing about Q_PROPERTYs. But since your orientation() returns an Orientation then as per the error message:

      '=': cannot convert from 'QLinearGradientCtrl::Orientation' to 'int'

      if you assign to * <int *> that is an int, won't you need to cast/convert Orientation to int for that to be acceptable to compiler?

      A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #5

      @JonB
      This line looks suspicious:

      Q_PROPERTY(int gradientWidth READ orientation WRITE setGradientWidth)
      

      Did you use the right getter?

      1 Reply Last reply
      4
      • PerdrixP Perdrix

        I have a class:

        class QLinearGradientCtrl : public QWidget
        {
        	Q_OBJECT
        	Q_PROPERTY(QLinearGradient gradient READ gradient WRITE setGradient)
        	Q_PROPERTY(int gradientWidth READ orientation WRITE setGradientWidth)
        	Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation)
        
        public:
        	enum Orientation
        	{
        		ForceHorizontal,
        		ForceVertical,
        		Auto
        	};
        

        I changed the enum to enum class Orientation, but that gave me:

        moc_QLinearGradientCtrl.cpp
        1>C:\Users\amonra\Documents\GitHub\DSS\DeepSkyStacker\GeneratedFiles\moc_QLinearGradientCtrl.cpp(199,65): error C2440: '=': cannot convert from 'QLinearGradientCtrl::Orientation' to 'int'
        

        What do I need to do to get this working?

        Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by Chris Kawa
        #2

        @Perdrix What's at line 199 in moc_QLinearGradientCtrl.cpp? What is the signature of orientation and setOrientation methods?

        1 Reply Last reply
        2
        • PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by
          #3

          Line 199:

                  case 1: *reinterpret_cast< int*>(_v) = _t->orientation(); break;
          
          

          Function sigs:

          	Orientation orientation() const { return m_Orientation; };
          	QLinearGradientCtrl &
          		setOrientation(Orientation orientation) { m_Orientation = orientation; return *this; };
          

          Thanks
          David

          JonBJ 1 Reply Last reply
          0
          • PerdrixP Perdrix

            Line 199:

                    case 1: *reinterpret_cast< int*>(_v) = _t->orientation(); break;
            
            

            Function sigs:

            	Orientation orientation() const { return m_Orientation; };
            	QLinearGradientCtrl &
            		setOrientation(Orientation orientation) { m_Orientation = orientation; return *this; };
            

            Thanks
            David

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @Perdrix
            I know nothing about Q_PROPERTYs. But since your orientation() returns an Orientation then as per the error message:

            '=': cannot convert from 'QLinearGradientCtrl::Orientation' to 'int'

            if you assign to * <int *> that is an int, won't you need to cast/convert Orientation to int for that to be acceptable to compiler?

            A 1 Reply Last reply
            0
            • JonBJ JonB

              @Perdrix
              I know nothing about Q_PROPERTYs. But since your orientation() returns an Orientation then as per the error message:

              '=': cannot convert from 'QLinearGradientCtrl::Orientation' to 'int'

              if you assign to * <int *> that is an int, won't you need to cast/convert Orientation to int for that to be acceptable to compiler?

              A Offline
              A Offline
              Asperamanca
              wrote on last edited by
              #5

              @JonB
              This line looks suspicious:

              Q_PROPERTY(int gradientWidth READ orientation WRITE setGradientWidth)
              

              Did you use the right getter?

              1 Reply Last reply
              4
              • PerdrixP Offline
                PerdrixP Offline
                Perdrix
                wrote on last edited by
                #6

                Arrggghhhh! Classic copy/paste error

                Mea maxima culpa :(

                D.

                A 1 Reply Last reply
                1
                • PerdrixP Perdrix

                  Arrggghhhh! Classic copy/paste error

                  Mea maxima culpa :(

                  D.

                  A Offline
                  A Offline
                  Asperamanca
                  wrote on last edited by
                  #7

                  @Perdrix said in Changing class local enum to enum class:

                  Arrggghhhh! Classic copy/paste error

                  Mea maxima culpa :(

                  D.

                  Been there, done that, won the swearing contest :-)

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved