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

Crash when accessing QScxmlEvent

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.5.2, 6.6.0
    • 6.5.0
    • PySide
    • None
    • Windows
    • e3d587288 (dev), 551e6d68e (dev), a31777a69 (6.5), be920de29 (6.5)

    Description

      Interacting with a QScxmlEvent, that has been sent by a state machine, crashes the application.  Reproduction code is below.

      I have quite a hard time finding any Python documentation or examples for this module. It would be nice if you could point me to something.

      On another related note: while digging into this issue, I found out that you could pass types to Slot() as strings. And as far as I know, it is even required in this case because otherwise QObject.connect() will not find the method.
      This is another feature that I could not find any documentation on.

      test.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="demo.scxml" qt:editorversion="10.0.1">
          <state id="init">
              <transition type="internal" target="main"/>
          </state>
          <state id="main">
              <onentry>
                  <send event="main_entered"/>
              </onentry>
          </state>
      </scxml>
      

      statemachine.py:

      from typing import cast
      
      from PySide6.QtCore import SLOT, QObject, Slot
      from PySide6.QtScxml import QScxmlEvent, QScxmlStateMachine
      from PySide6.QtWidgets import QApplication
      
      class StateMachineTest(QObject):
          def __init__(self, parent: QObject | None = None) -> None:
              super().__init__(parent)
              self.sm = QScxmlStateMachine.fromFile("test.scxml")
              self.sm.connectToEvent(
                  "main_entered",
                  self,
                  cast(bytes, SLOT(cast(bytes, "handle_event(QScxmlEvent)"))),
                  # double cast because type hints for both SLOT() and 
                  # QScxmlStateMachine.connectToEvent() are wrong.
              )
      
          # Slot type argument must be a string, or connect() will not find it
          @Slot("QScxmlEvent")
          def handle_event(self, event: QScxmlEvent) -> None:
              print(f"{event = }\n")
              print(f"{dir(event) = }\n")
              print(f"{event.name = }\n")  # OK up to here
              print(f"{event.name() = }\n")  # crashes here
      
      if __name__ == "__main__":
          app = QApplication()
          sm_test = StateMachineTest()
          sm_test.sm.start()
          app.exec()
      

      Attachments

        1. pyside2340_stack.txt
          148 kB
          Friedemann Kleint
        2. pyside2340_valgrind.txt
          162 kB
          Friedemann Kleint
        3. pyside2340.zip
          3 kB
          Friedemann Kleint
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kleint Friedemann Kleint
            maxxpower Markus Fleischhacker
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes