QML 静态分析 3 - Fixit 提示
在本章中,我们将学习如何通过添加修复提示来改进自定义警告。
到目前为止,我们只创建了警告消息。不过,有时我们还希望为用户提供如何修复代码的提示。为此,我们可以将FixSuggestion 的实例传递给emitWarning 。修复建议通常包含应修复的内容描述及其适用位置,还可以包含替换文本。 默认情况下,替换文本仅显示在诊断消息中。但通过在 `FixSuggestion` 上调用 `setAutoApplicable(true) `,用户可通过 qmllint 或 QML Language Server 自动应用该修复。重要的是,只有当生成的代码有效时,才应将该建议标记为“可自动应用”。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.