I wanted to use Qt State Machine QML in my PyQt 6 app, however when I try to run it, I get the following error:
QQmlApplicationEngine failed to load component
.../src/qml/Main.qml:8:1: module "QtQml.StateMachine" is not installed
Code:
import sys
from PyQt6.QtGui import QGuiApplication
from PyQt6.QtQml import QQmlApplicationEngine
from PyQt6.QtCore import QObject, pyqtSlot, pyqtSignal
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.quit.connect(app.quit)
engine.load('qml/Main.qml')
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec())
Window {
... // Qt State Machine QML Guide code
DSM.StateMachine {
id: stateMachine
// set the initial state
initialState: s1
// start the state machine
running: true
DSM.State {
id: s1
DSM.SignalTransition {
targetState: s2
signal: button.clicked
}
onEntered: console.log("s1 entered")
onExited: console.log("s1 exited")
}
DSM.State {
id: s2
onEntered: console.log("s2 entered")
onExited: console.log("s2 exited")
}
}
}
To run the app I use pip to install the following packages from requirements.txt
:
PyQt6
pyqt6-plugins
PyQt6-Qt6
PyQt6-sip
pyqt6-tools
python-dotenv
qt6-applications
qt6-tools
I think the issue is with some missing package not defined there.
I installed qt6-scxml package for Arch but I still get the same error and right now I am completely clueless.
Does anyone know what the missing pip package is?
Is it even possible to run it in PyQt6?
Apparently the state machine is supported in PySide6 and it’s unclear how it works in PyQt6