You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

按Qt文档配置QML模块后,qml.misc提示未安装求排查

Qt QML模块导入失败问题排查与修复

项目简化结构

./
│
├── qml/
│   ├── misc/
│   │   ├── SplashScreen.qml
│   │   └── qmldir
│   │
│   ├── main/
│   │   ├── Main.qml
│   │   └── qmldir
│   │
│   └ qmldir

各目录下qmldir文件内容

qml/目录下的qmldir

module qml

qml/misc/目录下的qmldir

module qml.misc
SplashScreen 1.0 SplashScreen.qml

qml/main/目录下的qmldir

module qml.main

resources.qrc文件内容

<!DOCTYPE RCC><RCC version="1.0">
    <qresource>
        <file alias="main">qml/main/Main.qml</file>
        <file>qml/main/qmldir</file>
    </qresource>
    <qresource prefix="/qml">
        <file>qmldir</file>
    </qresource>
</RCC>

Python代码配置

在main.py中为QML引擎添加导入路径:

path = "C:/Users/Bob/Repos/TestApp/qml"
self.engine.addImportPath(QUrl.fromLocalFile(path).toString())
print(self.engine.importPathList())  # 确认路径已添加在列表开头
...
self.engine.load(QUrl("qrc:/main"))

QML导入代码

在Main.qml中导入模块:

import QtCore
import QtQuick
import qml.misc

报错信息

ERROR: qrc:/main:3:1: module "qml.misc" is not installed

修复方案

手动编辑resources.qrc,添加所有.qml文件的路径后错误消失。此前误以为只需添加qmldir文件即可,实际上需要将模块相关的所有QML文件都加入资源文件中。

内容的提问来源于stack exchange,提问作者vilal32

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 18:25:07