Enum Sequence



  • 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.


  • Lifetime Qt Champion

    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



  • @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


  • Lifetime Qt Champion

    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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.