Qt Forum

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

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

    C++ Gurus
    2
    3
    1676
    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
      st2000 last edited by

      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(state_history_stack.top);@

      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
      {
      DEFAULT_CATEGORY,
      ALL_CATEGORY,
      };
      enumQueryState queryState;
      switch (queryState)@

      -thanks

      1 Reply Last reply Reply Quote 0
      • JohanSolo
        JohanSolo last edited by

        You should use :
        @switch(state_history_stack.top());@
        but I think that some compiler don't like enum in switch.

        `They did not know it was impossible, so they did it.'
        -- Mark Twain

        1 Reply Last reply Reply Quote 0
        • S
          st2000 last edited by

          D'oh - need more coffee.

          That worked!

          -thanks

          1 Reply Last reply Reply Quote 0
          • First post
            Last post