Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. OnEntry/OnExit/OnTransition signals for SCXML
Forum Updated to NodeBB v4.3 + New Features

OnEntry/OnExit/OnTransition signals for SCXML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 959 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.
  • PhrogzP Offline
    PhrogzP Offline
    Phrogz
    wrote on last edited by
    #1

    I have an application using an SCXML StateMachine. I want to receive signals in QML when I enter or exit particular states, or (stretch goal) when certain transitions are executed.

    According to this post I can emit a custom signal like so:
    <onentry><send type="qt:signal" event="enteredFoo"/></onentry>

    However, I cannot figure out how to actually connect to such a signal in QML. For example, the code at bottom (unsurprisingly) produces the error:
    TypeError: Cannot call method 'connect' of undefined

    How can I detect when the state machine enters or exits a state?

    import QtQuick 2.7
    import QtScxml 5.8
    
    Window {
        visible: true
        property StateMachine logic: logicLoader.stateMachine
        StateMachineLoader { id:logicLoader; source:"main.scxml" }
        Component.onCompleted: {
            logic.enteredFoo.connect(function(){
                console.log('w000t');
            });
        }
    }
    
    1 Reply Last reply
    0
    • PhrogzP Offline
      PhrogzP Offline
      Phrogz
      wrote on last edited by Phrogz
      #2

      Of course the answer is RTFM :)

      The documentation on state machines mentions the EventConnection type. This emits a single occurred signal when specific, listed SCXML events occur (fired without the type="qt:signal" attribute), and allows patterns like:

      property StateMachine logic: logicLoader.stateMachine
      StateMachineLoader { id:logicLoader; source:"main.scxml" }
      EventConnection {
          signal enteredFoo(var event)
          signal enteredBar(var event)
          stateMachine: logic
          events: ["enteredFoo", "enteredBar"]
          onOccurred: this[event.name](event);
      }
      

      This requires you to manually enter the enter/exit/transition event three times:

      • In the SCXML as a send action
      • In the EventConnection as a signal
      • In the events list in the EventConnection

      ...but it does work!

      Hey Qt! Please add a better way to do this! :)

      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