Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Enum Sequence

    General and Desktop
    qt5
    2
    4
    753
    Loading More Posts
    • 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
      Sebastian last edited by Sebastian

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • S
          Sebastian last edited by

          @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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 1
            • First post
              Last post