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. Qt signal transition on parent state overriden by child state
Forum Updated to NodeBB v4.3 + New Features

Qt signal transition on parent state overriden by child state

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 162 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.
  • C Offline
    C Offline
    co2fgtr
    wrote on last edited by
    #1

    In my QStateMachine, I have a QState parent that has several children states child1, child2 and child3. I want all children to have a common response to the signal MyStruct::mySignal(). However, I also want child1 to do something more on that signal. I thought of creating a QSignalTransition on the parent with the common response, and creating another one with the specific behavior for child1 (see the code below).

    struct MyStruct {
      Q_OBJECT
    
      Q_SIGNAL void mySignal();
    
      void commonResponse() {
        std::cout << "Common" << std::endl;
      }
    
      void specificResponse() {
        std::cout << "Specific" << std::endl;
      }
    };
    
    QState* parent = new QState();
    QState* child1 = new QState(parent);
    QState* child2 = new QState(parent);
    QState* child3 = new QState(parent);
    
    MyStruct myStruct;
    
    QSignalTransition* commonTransition = new QSignalTransition(&myStruct, &MyStruct::mySignal);
    parent->addTransition(commonTransition);
    connect(commonTransition , &QAbstractTransition::triggered, &myStruct, &MyStruct::commonResponse);
    
    QSignalTransition* specificTransition = new QSignalTransition(&myStruct, &MyStruct::mySignal);
    child1->addTransition(specificTransition);
    connect(specificTransition, &QAbstractTransition::triggered, &myStruct, &MyStruct::specificResponse);
    

    However with this code, if I am currently in state child1 and a MyStruct::mySignal is emitted, then it will only output Specific, because the transition is overriden. Is it possible to get the expected behavior of printing both Common and Specific while keeping the code clarity? (without adding a duplicate MyStruct::mySignal for the specific case, or having to "remember" to call commonResponse in specificResponse)

    It's too bad there is not some kind of parameter on the QSignalTransition that would act like "do not override the transition and allow new similar ones to be executed along with this one".

    It is a duplicate of my original question on StackOverflow. Maybe you guys have a solution for me. Or at least maybe the devs will hear what I want to do and maybe add that feature :)

    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