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. QStateMachine: How to add a condition for transitions?
Forum Updated to NodeBB v4.3 + New Features

QStateMachine: How to add a condition for transitions?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.2k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    Tabi
    wrote on last edited by
    #1

    I have a state machine that make transition, say T1, on leave event of a frame, that transition result in hiding of the frame. Now I added a QComboBox in the frame. But when I opens the box it the frame leave event invoked so frame disappeared and hence box too. Now I want to add condition that when transition one gonna happen state machine should check if enter event of combobox invoked or not. How to do this? Or There is a btter way to do this?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      You just need to route the transition through a custom slot where you check your condition and emit a signal which triggers the state change.
      So actually you decide when to switch to another state and thus you can check for an arbitrary condition.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tabi
        wrote on last edited by
        #3

        can you please give a piece of code or any lick that explains concept.

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          taken from the "docs":http://qt-project.org/doc/qt-4.8/qstatemachine.html#details:
          [quote]
          QPushButton button;

          QStateMachine machine;
          QState *s1 = new QState();
          s1->assignProperty(&button, "text", "Click me");

          QFinalState *s2 = new QFinalState();
          s1->addTransition(&button, SIGNAL(clicked()), s2);

          machine.addState(s1);
          machine.addState(s2);
          machine.setInitialState(s1);
          machine.start();
          [/quote]

          as you can see in the line:
          @
          ...->addTransition(&button, SIGNAL(clicked()), s2);
          @
          You can decide when to advance to a new state/transition with a signal.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tabi
            wrote on last edited by
            #5

            But it is not invoking slot. If I use a custom signal I have to emit it for which I have to invoke another slot again and that should be invoked by checking of enter event of qcombobox. complicated one, is it possible to check enter event of child widget at time of transition.

            1 Reply Last reply
            0

            • Login

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