Handling incorrect warnings and a limited functionality in QML Code Editor in Qt Creator 14.0 and 15.0
处理Qt Creator 14.0和15.0中QML代码编辑器中的错误警告和限制功能
December 16, 2024 by Sami Shalayel | Comments
2024年12月16日,萨米·沙拉耶勒发表|评论
We've recently discovered that the QML code editor in Qt Creator 14.0 and 15.0 is not working as expected out of the box. The QML Language Server integration is currently broken, and we’d like to address it openly and provide solutions for those affected.
我们最近发现Qt Creator 14.0和15.0中的QML代码编辑器无法按预期开箱即用。QML语言服务器集成目前已损坏,我们希望公开解决这个问题,并为受影响的人提供解决方案。
The issue
问题
Qt projects targeting Qt 6.8 have lots of warnings when opened in Qt Creator, despite still building and running fine. The problem was introduced while transitioning Qt Creator from the embedded codemodel to QML Language Server.
以Qt 6.8为目标的Qt项目在Qt Creator中打开时会出现很多警告,尽管仍然可以构建和运行良好。该问题是在将Qt Creator从嵌入式代码模型转换到QML语言服务器时引入的。
What happened?
怎么搞的?
In Qt Creator 14.0, we introduced the QML Language Server as the default mechanism for features such as warnings, autocompletion, and navigation (“Go to Definition”). While this modern integration offers numerous benefits, it relies on build folder information to resolve user-defined or custom QML modules. This information is essential for accurate imports and proper functionality.
在Qt Creator 14.0中,我们引入了QML语言服务器作为警告、自动补全和导航(“转到定义”)等功能的默认机制。虽然这种现代集成提供了许多好处,但它依赖于构建文件夹信息来解析用户定义或自定义的QML模块。此信息对于准确导入和正常功能至关重要。
Due to an oversight on our part, the necessary build folder data was not passed to the QML Language Server. As a result, many projects show incorrect warnings, and key features like autocompletion and navigation are not working as intended.
由于我们的疏忽,必要的构建文件夹数据没有传递给QML语言服务器。因此,许多项目显示了不正确的警告,自动补全和导航等关键功能也没有按预期工作。
How does this impact you?
这有什么影响?
If you’re using Qt Creator 14.0 or 15.0 with projects that include custom or user-written QML modules:
如果将Qt Creator 14.0或15.0用于包含自定义或用户编写的QML模块的项目:
- You may see incorrect warnings indicating that QML modules cannot be imported or that their properties, methods, or types are unresolved.
- 可能会看到错误的警告,指示QML模块无法导入或其属性、方法或类型未解析。
- Features like autocompletion and navigation may not function properly.
- 自动补全和导航等功能可能无法正常工作。
Even with the above issues, your projects will still build and run correctly. We will provide a permanent fix for these issues. The next section describes a workaround to improve your situation right now.
即使有上述问题,项目仍将正确构建和运行。我们将为这些问题提供永久解决方案。下一节将介绍一种解决方法,以改善现在的情况。
Workarounds
权变措施
To mitigate this issue, we recommend the following workarounds until Qt Creator 16 is released:
为了缓解这个问题,我们建议在Qt Creator 16发布之前采取以下解决方法:
Configure QML Language Server using QT_QML_GENERATE_QMLLS_INI
使用QT_QML_GENERATE_QMLLS_INI配置QML语言服务器
You can manually provide the missing build folder information to the QML Language Server via CMake. To achieve that:
可以通过CMake手动向QML语言服务器提供缺少的构建文件夹信息。为了实现这一目标:
1.Go to Projects
> Build
> CMake
> Add
1.转到项目>构建>CMake>添加
2.Create a QT_QML_GENERATE_QMLLS_INI
variable, set it to ON
, and press Run CMake
2.创建QT_QML_GENERATE_QMLLS_INI变量,将其设置为ON,然后按Run CMake
3.Restart the language Server
3.重新启动语言服务器
Note that QT_QML_GENERATE_QMLLS_INI
is not yet supported on Boot2Qt projects.
请注意,Boot2Qt项目尚不支持QT_QML_GENERATE_QMLLS_INI。
Revert to the embedded code model
恢复到嵌入式代码模型
You can enable the embedded code model by disabling QML Language Server in the Qt Creator settings,. This allows to use the older system for warnings, autocompletion, navigation, and other features, but has the drawback that some of the "real warnings" won't be shown in that case.
可以通过在Qt Creator设置中禁用QML语言服务器来启用嵌入式代码模型,。这允许使用旧系统进行警告、自动补全、导航和其他功能,但有一个缺点,即在这种情况下,一些“真正的警告”不会显示出来。
What’s next?
接下来是什么?
The upcoming Qt Creator 16.0 will include a reworked QML Language Server integration, ensuring that the necessary build folder information is passed correctly. This will restore functionality and resolve the current issues.
即将推出的Qt Creator 16.0将包括重新设计的QML语言服务器集成,确保正确传递必要的构建文件夹信息。这将恢复功能并解决当前的问题。
We are also reviewing our internal processes to ensure that such oversights will be identified as early as possible and avoided in the future so that they don't impact you as users.
我们也在审查我们的内部流程,以确保尽早发现并避免此类疏忽,以免影响用户。
Technical details
技术细节
The QML Language Server management in Qt Creator 14.0 and 15.0 is sharing the same qmlls
instance across all projects. qmlls
is started as soon as a QML file is opened, and then keeps running until Qt Creator is exited. This is very impractical if each project needs to run qmlls
with its own set of command line parameters including the build folder, and therefore required deeper changes before being able to supply an actual fix. You can follow the current development of the new QML Language Server management code at QTCREATORBUG-31897, which includes passing the build folder to qmlls
.
Qt Creator 14.0和15.0中的QML语言服务器管理在所有项目中共享相同的qmls实例。qmls在QML文件打开后立即启动,然后继续运行,直到退出Qt Creator。如果每个项目都需要使用自己的一组命令行参数(包括构建文件夹)运行qmls,因此需要进行更深入的更改才能提供实际的修复,那么这是非常不切实际的。可以在QTCREATORBUG-31897上跟踪新QML语言服务器管理代码的当前开发,其中包括将构建文件夹传递给qmls。
Thank You for Your Patience
感谢你的耐心
We apologize for the inconvenience and confusion this issue may have caused. We greatly value your feedback and appreciate your understanding as we work to improve Qt Creator and deliver the experience you deserve.
对于此问题可能造成的不便和混乱,我们深表歉意。我们非常重视反馈,并感谢您的理解,因为我们正在努力改进Qt Creator并提供应得的体验。
If you have any questions or need further assistance, please don’t hesitate to reach out to us.
如果有任何问题或需要进一步的帮助,请随时与我们联系。