Important: Please read the Qt Code of Conduct -

[SOLVED] Can I create a QStack of the same type as my enum type?

  • Hi...

    I have a program which is working well. I created an enum type variable and am using that variable in a select/case statement. Now Qt and C++ are doing a great job at keeping me honest.

    But I wish to now use a QStack to hold the enum variable:
    @ QStack<enumQueryState> state_history_stack;@
    This so I can keep a history of my states. That is I though I could now push the current state onto the stack and pop off a state should I want to travel backwards through the states. Well I just can not get the following select/case statement line to compile:
    @ switch(;@

    error: "switch quantity not an integer"

    Is there a problem with Qt or C++? Is there something I don't understand with regards to the QStack?

    Remember, I said this program was working well. That is, these lines compile and execute just the way I would expect:
    @ enum enumQueryState
    enumQueryState queryState;
    switch (queryState)@


  • You should use :
    but I think that some compiler don't like enum in switch.

  • D'oh - need more coffee.

    That worked!


Log in to reply