Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-851

QScxmlStateMachine: Unable to pass arguments to events

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.11.2
    • PySide
    • None
    • macOS

    Description

      I'm trying to pass arguments to functions connected to events. The documentation of PySide2.QtScxml.QScxmlStateMachine.connectToEvent [1] says:

      The receiver’s method may take a PySide2.QtScxml.QScxmlEvent as a parameter

      See the demo code below.

      This example code outputs:

      QObject::connect: Incompatible sender/receiver arguments
      QScxmlInternal::ScxmlEventRouter::eventOccurred(QScxmlEvent) --> Backend::my_event(int)

      If I try to change the int argument by QScxmlEvent, it outputs:

      QObject::connect: No such slot Backend::my_event(QScxmlEvent)

      If I set no argument, it works, but there is no argument (args and kwargs empty).

      [1] https://doc.qt.io/qtforpython/PySide2/QtScxml/QScxmlStateMachine.html#PySide2.QtScxml.PySide2.QtScxml.QScxmlStateMachine.connectToEvent

      demo.scxml:

      <?xml version="1.0" encoding="UTF-8"?>
      <scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" binding="early" name="demo.scxml">
          <transition type="internal" event="MY_EVENT"/>
          <state id="StateMachine"/>
      </scxml>
      

       demo.py:

      #!/usr/bin/env python
      
      import sys
      
      from PySide2.QtCore import QObject, QCoreApplication, SLOT, Slot
      from PySide2.QtScxml import QScxmlStateMachine, QScxmlEvent
      
      
      class Backend(QObject):
          def __init__(self, machine):
              super(Backend, self).__init__()
              self.machine = machine
              self.machine.connectToState('StateMachine', self, SLOT('state_machine_active(bool)'))
              self.machine.connectToEvent('MY_EVENT', self, SLOT('my_event(int)'))
      
          @Slot(bool)
          def state_machine_active(self, active):
              print('StateMachine::active: %s' % active)
              self.machine.submitEvent('MY_EVENT')
      
          @Slot(int)
          def my_event(self, *args, **kwargs):
              print('MY_EVENT:', args, kwargs)
      
      
      if __name__ == '__main__':
          app = QCoreApplication(sys.argv)
      
          machine = QScxmlStateMachine.fromFile('demo.scxml')
          b = Backend(machine)
          machine.start()
      
          sys.exit(app.exec_())
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            rledisez Romain LE DISEZ
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes