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.