Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Enum Sequence
Qt 6.12 LTS is out! See what's new in the release blog

Enum Sequence

Scheduled Pinned Locked Moved General and Desktop
qt5
4 Posts 2 Posters 1.8k Views 2 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.
  • S Offline
    S Offline
    Sebastian
    wrote on last edited by Sebastian
    #1

    Dear All,
    suppose I have Qflags. I want to know in which sequence the enum value is added.for eg.
    class MyClass: public QObject
    {
    Q_OBJECT

    public:
    explicit MyClass(QObject *parent = 0);
    ~MyClass();

    enum Sequence{
        one  = 1,
        two = 2,
        three = 3
     
    };
    Q_DECLARE_FLAGS(NumSequence, Sequence)
    
    NumSequence m_Flag;
    void setFlag(NumSequence &value)
     {
                 m_Flag= value;
     }
    

    };
    Q_DECLARE_OPERATORS_FOR_FLAGS(MyClass::NumSequence)

    Eg: MyClass myClassObj;
    myClassObj.setFlag(MyClass::three || MyClass::one );

    In this example my code should give me that MyClass::three was the first value.

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

      Hi and welcome to devnet,

      Your enum declaration is wrong if you want to create flags from it.

      enum Sequence{
          one  = 0x01,
          two = 0x02,
          three = 0x04
      };
      

      3 being 11 in base 2, it would been that you have both one and two set

      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
      • S Offline
        S Offline
        Sebastian
        wrote on last edited by
        #3

        @Sebastian said:

        nt to know in which sequence the enum value is added.for eg.
        class MyClass: public QObject

        thanks for your reply.
        but i want to know the sequence of enum is added.for the above example how should i know that MyClass::three was the first value was the first value of mine.........and after that MyClass::one was the second value ...???(I want to know the sequence).

        thanks again @SGaist

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

          Then you're using the wrong tool, flags don't have any notion of input order. If you want a FIFO behavior you should rather use a container like QQueue

          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
          1

          • Login

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