Details
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
For Gerrit Dashboard: PYSIDE-2340 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
480870,2 | Fix crash when using QScxmlStateMachine::connectToEvent() | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
480920,2 | Fix crash when using QScxmlStateMachine::connectToEvent() | 6.5 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
482526,5 | PySide6: Fix a few type hints of functions taking a str | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
482539,2 | PySide6: Fix a few type hints of functions taking a str | 6.5 | pyside/pyside-setup | Status: MERGED | +2 | 0 |