QML 静态分析 3 - Fixit 提示
在本章中,我们将学习如何使用 fixit 提示来改进自定义警告。
到目前为止,我们只创建了警告信息。不过,有时我们也想为用户添加如何修复代码的提示。为此,我们可以向emitWarning 传递FixSuggestion
的实例。修复建议总是包含对应该修复的内容的描述,以及应该应用的位置。它还可以包含替换文本。默认情况下,替换文本只显示在诊断信息中。通过在FixSuggestion
上调用setAutoApplicable(true)
,用户可通过 qmllint 或 QML Language Server 自动应用修复。重要的是,只有在生成的代码有效时,才能将建议标记为可自动应用。
© 2025 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.