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. Serializing custom global enum type in custom class
Forum Updated to NodeBB v4.3 + New Features

Serializing custom global enum type in custom class

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.7k 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.
  • M Offline
    M Offline
    Misty River
    wrote on last edited by
    #1

    Hi, I have a global enum type defined outside of a class that contains a private property of that type.. now I would like to serialize that class in a qbytearray.. how can this be done?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean using something like QDataStream ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Misty River
        wrote on last edited by
        #3

        Hi, yes that is exactly what I mean! I have a class that I need to serialize with a QDataStream and it contains enum types (which are global not local to the class).. I know it can be done if the class inherits QOject and the enum is local to the class by QMetaObject but it's kinda tricky in that case.. If you know how to achieve that please share.. cuz right now the only solution I have is making the properties as qint which works fine but not quite what I wanted to do

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          One of solutions:
          @QDataStream &operator <<(QDataStream &out, const MyClass &packet)
          {
          out <<quint8(packet.enumValue);
          return out;
          }

          QDataStream &operator >>(QDataStream &in, MyClass &packet)
          {
          packet = MyClass();
          quint8 tempVal;
          in >> tempNpt;
          packet.enumValue = enumType(tempVal);
          return in;
          }@

          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