Skip to content
  • 0 Votes
    3 Posts
    87 Views
    Pl45m4P

    @JonB

    Thanks for your reply.
    Will see what I can do

    The struggle is actually to figure out what I can use without leading to further issues later.

    Currently I'm fine with a counter and then fire my signal once it reaches 0.

  • 0 Votes
    10 Posts
    3k Views
    C

    @QtQrustacean You may need to re-install Qt. I installed the default Qt for Desktop Applications from the installer (6.1.2), and had the same problem you did. By deleting that version of Qt and doing the Custom build, I was able to select Qt 6.1.2 and then add the Qt StateMachine package in the same area. So far, what I did is working.

  • 0 Votes
    2 Posts
    653 Views
    R

    By writing a small demo to complete my post, I found the issue. As it might be helpful to somebody else, here it is:

    demo.scxml:

    <?xml version="1.0" encoding="UTF-8"?> <scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" binding="early" xmlns:qt="http://www.qt.io/2015/02/scxml-ext" name="plop.scxml" qt:editorversion="4.7.1"> <state id="State_1"> <qt:editorinfo scenegeometry="144.50;162.05;84.50;112.05;120;100" geometry="144.50;162.05;-60;-50;120;100"/> </state> </scxml>

    demo.py:

    #!/usr/bin/env python import sys from PySide2.QtCore import QObject, QCoreApplication, SLOT, Slot from PySide2.QtScxml import QScxmlStateMachine class Backend_1(QObject): def __init__(self, machine): super(Backend_1, self).__init__() self.machine = machine self.machine.connectToState("State_1", self, SLOT("s1_active(bool)")) @Slot(bool) def s1_active(self, active): if active: print('Backend_1::State_1: enter') self.submachine = QScxmlStateMachine.fromFile('demo.scxml') b = Backend_2(self.submachine) self.submachine.start() else: print('Backend_1::State_1: exit') class Backend_2(QObject): def __init__(self, machine): super(Backend_2, self).__init__() self.machine = machine self.machine.connectToState("State_1", self, SLOT("s1_active(bool)")) @Slot(bool) def s1_active(self, active): if active: print('Backend_2::State_1: enter') else: print('Backend_2::State_1: exit') if __name__ == '__main__': app = QCoreApplication(sys.argv) machine = QScxmlStateMachine.fromFile('demo.scxml') b = Backend_1(machine) machine.start() sys.exit(app.exec_())

    If you run this, you expect to see:
    Backend_1::State_1: enter
    Backend_2::State_1: enter

    But, the second statemachine does not seem to start. To fix it, you need to store the instance of Backend_2 (eg: self.b = Backend_2(self.submachine)). I guess it was garbage collected, so all the states/events connections were broken.

    Meanwhile, if you think my design patter is bad, I'm willing to learn :)

  • 0 Votes
    9 Posts
    3k Views
    A

    @VRonin : yes, but the system is rather complex and i want to use the statemachine framwork to implement it).
    By the way this same signal might require other actions in some of the other states
    Thanks a lot for your time

  • 0 Votes
    2 Posts
    640 Views
    SGaistS

    Hi,

    You are emitting the signals before all the event loops have started.