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
Forum Update on Monday, May 27th 2025

Enum class sample

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 668 Views
  • 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.
  • K Offline
    K Offline
    Kutyus
    wrote on 29 Nov 2019, 13:07 last edited by
    #1

    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

    O J 2 Replies Last reply 29 Nov 2019, 13:10
    0
    • K Kutyus
      29 Nov 2019, 13:07

      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

      O Offline
      O Offline
      ODБOï
      wrote on 29 Nov 2019, 13:10 last edited by ODБOï
      #2
      This post is deleted!
      1 Reply Last reply
      1
      • K Offline
        K Offline
        Kutyus
        wrote on 29 Nov 2019, 13:24 last edited by
        #3

        Same result

        1 Reply Last reply
        0
        • K Kutyus
          29 Nov 2019, 13:07

          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 Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 29 Nov 2019, 13:32 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
          • K Offline
            K Offline
            Kutyus
            wrote on 29 Nov 2019, 13:33 last edited by
            #5

            QObject included the top of header file

            J 1 Reply Last reply 29 Nov 2019, 13:35
            0
            • K Kutyus
              29 Nov 2019, 13:33

              QObject included the top of header file

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 29 Nov 2019, 13:35 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
              • K Offline
                K Offline
                Kutyus
                wrote on 29 Nov 2019, 13:39 last edited by
                #7

                Ohh Q_GADGET :) I will try

                J 1 Reply Last reply 29 Nov 2019, 13:41
                0
                • K Kutyus
                  29 Nov 2019, 13:39

                  Ohh Q_GADGET :) I will try

                  J Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 29 Nov 2019, 13:41 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.

                  K 1 Reply Last reply 29 Nov 2019, 13:54
                  1
                  • K Offline
                    K Offline
                    Kutyus
                    wrote on 29 Nov 2019, 13:50 last edited by
                    #9

                    Same error :(

                    1 Reply Last reply
                    0
                    • J J.Hilk
                      29 Nov 2019, 13:41

                      @Kutyus actually more importantly

                      class Ble: public QObject

                      to

                      class Ble

                      K Offline
                      K Offline
                      Kutyus
                      wrote on 29 Nov 2019, 13:54 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 1 Reply Last reply 29 Nov 2019, 13:56
                      0
                      • K Kutyus
                        29 Nov 2019, 13:54

                        @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 Offline
                        J Offline
                        J.Hilk
                        Moderators
                        wrote on 29 Nov 2019, 13:56 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
                        • K Offline
                          K Offline
                          Kutyus
                          wrote on 29 Nov 2019, 14:09 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

                          1/12

                          29 Nov 2019, 13:07

                          • Login

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