Live observation of state machines in a Qt application



  • Hello everybody,

    I'm trying to extract all the state machines of my application which are defined as DSM in QML.
    For documentation purposes I want to visualize the state machines and active states while the application is running (maybe with Graphviz like Gamma Ray does it).

    My first attempt was to install a eventFilter into my QGuiApplication and listen to all QChildEvents to recognize states added to a statemachine. Then I would build the state machines on my own and visualize them.

    bool FilterObject::eventFilter(QObject *object, QEvent *event)
    {
        if (event->type() == QEvent::ChildAdded) {
            QChildEvent *childAddedEvent = static_cast<QChildEvent*>(event);
    
            childAddedEvent->child()->installEventFilter(new FilterObject());
    
            qDebug() << "added" << childAddedEvent->child()->metaObject()->className() << "to" << object->metaObject()->className();
       
        }
    }
    

    Unfortunately I get mostly.

    • added QObject to ...
    • added QObject to ...
    • added QObject to ...

    So I can't really determine the if a QState is added to the state machine.

    Inherit QStatemachine, QState, ... and implement everything I need to access the state machines from outside could be an alternative way, but maybe there is an easier method.

    Do have any idea how I can observe my state machines without an external tool and maybe without the knowledge about the state machines.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Are you sure a tool like KDAB's Gamma Ray is out of question for your job ?



  • Hi,

    Yes, GammaRay might solve the problem, but I want to automate the process as much as possible.
    Example: I press a button in my application -> a screenshot of the application and all state machines are saved.

    With GammaRay I have to save the images of the state machines by hand (not .scxml or at least .dot)


  • Lifetime Qt Champion

    Then you should either check the code where they do that and integrated it to your project or add the image saving feature to GammaRay


Log in to reply
 

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