Skip to content

rules-qml:生成构建元数据,让 qmlls 能识别项目中的 QML 模块 #67

Backlog

Description

@yizhinailong

问题
用 mcpp.rules.qml 构建的 Qt Quick 应用可以正常运行,QML 也能调用通过 QML_ELEMENT 注册的 C++ 类型。但在 VS Code 中打开同一份 QML 文件时,Qt 语言服务器 qmlls 找不到项目模块,即使刚执行过 mcpp build。

复现步骤

  1. 声明一个 BeatLight QML 模块,其中包含用 QML_ELEMENT 注册的 C++ 类型 BeatCounter。
  2. 在 CounterPage.qml 中写入 import BeatLight,并实例化 BeatCounter {}。
  3. 执行 mcpp build,然后用 Qt 6.11.1 的 qmlls 打开该文件,不额外配置导入路径。

编辑器报告 Failed to import BeatLight 和 BeatCounter was not found。手动将生成的导入目录传给 -I 后,BeatCounter 可以识别,但仍提示 qmldir 列出的 Main.qml 和 CounterPage.qml 不在对应目录中。

期望行为
希望 mcpp build 生成 qmlls 可读取的 .qt/.qmlls.build.ini,并确保其中的导入路径、.qrc 资源映射与模块文件位置一致。这样编辑器只需将 --build-dir 指向一个稳定的构建目录,不必硬编码 target/.build-mcpp/out//...,也不需要改动运行时部署方式。

验证
在临时构建目录补齐上述元数据和模块文件布局后,使用 qmlls --build-dir <目录> --no-cmake-calls 打开同一个 CounterPage.qml,诊断从 3 条降为 0 条。

复现环境:Windows x64、mcpp 2026.11.22.1、mcpp.plugins 0.27.0、Qt 6.11.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions