PyQT 应用程序中未安装模块“QtQml.StateMachine”

问题描述 投票:0回答:1

我想在我的 PyQt 6 应用程序中使用 Qt State Machine QML,但是当我尝试运行它时,出现以下错误:

QQmlApplicationEngine failed to load component
.../src/qml/Main.qml:8:1: module "QtQml.StateMachine" is not installed

代码:

  • main.py:
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())
  • qml/Main.qml:
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")
        }
    }

}

要运行该应用程序,我使用 pip 从

requirements.txt
安装以下软件包:

PyQt6
pyqt6-plugins
PyQt6-Qt6
PyQt6-sip
pyqt6-tools
python-dotenv
qt6-applications
qt6-tools

我认为问题在于缺少一些未定义的软件包。

我为 Arch 安装了 qt6-scxml 包,但我仍然遇到同样的错误,现在我完全一无所知。

有人知道丢失的pip包是什么吗?

是否可以在 PyQt6 中运行它?

python qt qml pyqt6 qt6
1个回答
0
投票

显然 PySide6 支持状态机,但尚不清楚它在 PyQt6 中如何工作

© www.soinside.com 2019 - 2024. All rights reserved.