模块 "QtQuick.XmlListModel" 没有安装?

module "QtQuick.XmlListModel" is not installed?

我使用 PyQt6 并尝试 运行 一些 qml 应用程序,它抛出 module "QtQuick.XmlListModel" is not installed 错误?

Name: PyQt6
Version: 6.2.0
Summary: Python bindings for the Qt cross platform application toolkit
Home-page: https://www.riverbankcomputing.com/software/pyqt/
Author: Riverbank Computing Limited
Author-email: info@riverbankcomputing.com
License: GPL v3
Location: c:\users\administrator\appdata\local\programs\python\python310\lib\site-packages
Requires: PyQt6-Qt6, PyQt6-sip
Required-by:

代码段

import QtQuick 2.12
import QtQuick.XmlListModel 2.12

在 Qt6 中,XmlListModel 已从 QtQuick 移至 QtQml,如 the docs 中所示,因此您必须更改为:

import QtQuick
import QtQml.XmlListModel

注意:在 Qt6 中,您不应指示模块的版本。