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. Enum class sample
Qt 6.11 is out! See what's new in the release blog

Enum class sample

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 1.3k Views 1 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.
  • KutyusK Kutyus

    Hi!

    I would like to use an enum class, this is in an included header:

    class Ble: public QObject
    {
    	Q_OBJECT
    		
    public:
    	enum Message
    	{
    		hubproperty			= 0x01,
    		hubattachedio		= 0x04,
    		hwnetworkcommand	= 0x08,
    		portinputformat		= 0x41,
    		portvalue			= 0x45
    	};
    	Q_ENUM(Message)
    };
    

    The compiler give this error:

    undefined reference to `Ble::staticMetaObject'
    

    Thanks in advance

    ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by ODБOï
    #2
    This post is deleted!
    1 Reply Last reply
    1
    • KutyusK Offline
      KutyusK Offline
      Kutyus
      wrote on last edited by
      #3

      Same result

      1 Reply Last reply
      0
      • KutyusK Kutyus

        Hi!

        I would like to use an enum class, this is in an included header:

        class Ble: public QObject
        {
        	Q_OBJECT
        		
        public:
        	enum Message
        	{
        		hubproperty			= 0x01,
        		hubattachedio		= 0x04,
        		hwnetworkcommand	= 0x08,
        		portinputformat		= 0x41,
        		portvalue			= 0x45
        	};
        	Q_ENUM(Message)
        };
        

        The compiler give this error:

        undefined reference to `Ble::staticMetaObject'
        

        Thanks in advance

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #4

        @Kutyus

        
        #include <QObject>
        
        class Ble
        {
        	Q_GADGET
        		
        public:
        	enum Message
        	{
        		Hubproperty			= 0x01,
        		Hubattachedio		= 0x04,
        		Hwnetworkcommand	= 0x08,
        		Portinputformat		= 0x41,
        		Portvalue			= 0x45
        	};
        	Q_ENUM(Message)
        };
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        2
        • KutyusK Offline
          KutyusK Offline
          Kutyus
          wrote on last edited by
          #5

          QObject included the top of header file

          J.HilkJ 1 Reply Last reply
          0
          • KutyusK Kutyus

            QObject included the top of header file

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #6

            @Kutyus did you noticed the other changes in my post?


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • KutyusK Offline
              KutyusK Offline
              Kutyus
              wrote on last edited by
              #7

              Ohh Q_GADGET :) I will try

              J.HilkJ 1 Reply Last reply
              0
              • KutyusK Kutyus

                Ohh Q_GADGET :) I will try

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #8

                @Kutyus actually more importantly

                class Ble: public QObject

                to

                class Ble


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                KutyusK 1 Reply Last reply
                1
                • KutyusK Offline
                  KutyusK Offline
                  Kutyus
                  wrote on last edited by
                  #9

                  Same error :(

                  1 Reply Last reply
                  0
                  • J.HilkJ J.Hilk

                    @Kutyus actually more importantly

                    class Ble: public QObject

                    to

                    class Ble

                    KutyusK Offline
                    KutyusK Offline
                    Kutyus
                    wrote on last edited by
                    #10

                    @J-Hilk This error is produced by linker, in the object file, where is this line:

                    QMetaEnum::fromType<Ble::Message>().valueToKey(m)
                    

                    m is a message code integer.

                    J.HilkJ 1 Reply Last reply
                    0
                    • KutyusK Kutyus

                      @J-Hilk This error is produced by linker, in the object file, where is this line:

                      QMetaEnum::fromType<Ble::Message>().valueToKey(m)
                      

                      m is a message code integer.

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #11

                      @Kutyus
                      https://github.com/DeiVadder/Topic109331

                      working class


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      2
                      • KutyusK Offline
                        KutyusK Offline
                        Kutyus
                        wrote on last edited by
                        #12

                        @Kutyus said in Enum class sample:

                        QMetaEnum::fromTypeBle::Message().valueToKey(m)

                        When I comment out the line wich contains the QMetaEnum::fromTypeBle::Message().valueToKey(m), the code is compiled succes.
                        How can i get the enum name from its value?

                        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