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 Sequence

Enum Sequence

Scheduled Pinned Locked Moved General and Desktop
qt5
4 Posts 2 Posters 922 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.
  • S Offline
    S Offline
    Sebastian
    wrote on 3 May 2015, 13:09 last edited by Sebastian 5 Mar 2015, 13:41
    #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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 May 2015, 21:56 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 5 May 2015, 06:54 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 5 May 2015, 07:11 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

          1/4

          3 May 2015, 13:09

          • Login

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