检查代码语法
在您编写代码时,Qt Creator 会检查代码语法。当Qt Creator 发现您代码中的语法错误时,它会用下划线标出,并显示一个图标,当鼠标指针移到错误或图标上时,还会显示错误详情。要应用可用的修复程序,请选择 。
同样,当您正在处理 JavaScript 对象符号 (JSON) 实体的实例时,Qt Creator 会在 JSON 数据结构中的错误下划线。
C++ 代码错误示例
Qt Creator 注释错误,因为行尾缺少分号:
Qt Creator 因未使用变量而发出警告:
Qt 类名有错别字:
检查 QML 或 JavaScript 语法
编写 QML 或 JavaScript 代码时,注释可能会有错误代码。
如果为一个项目打开QML Language Server ,它就会使用qmllint
检查 QML 和 JavaScript 代码。更多信息,请参阅qmllint Reference。
如果关闭QML Language Server ,Qt Creator 会使用静态分析器。更多信息,请参阅JavaScript 和 QML 错误代码。
管理消息
使用工具提示弹出窗口中的图标,可将错误或警告信息复制到剪贴板,隐藏特定类型的信息,或更改诊断设置。
要修改用于下划线显示错误和警告的颜色,请执行以下操作
- 转到首选项>Text Editor >Font & Colors >。Copy
- 为Error 和Warning 选择新颜色。
设置行注释位置
要指定注释的显示位置,请转到首选项>Text Editor >Display >Line Annotations ,然后选择是直接在代码旁边显示注释,还是在代码右边对齐,或者在右边空白处显示。如果通常没有足够的空间在文本旁边显示注释,在行间显示注释可能会很有用。
如果隐藏了注释,可以将鼠标指针移到图标上查看。
另请参阅 JavaScript 和 QML 检查、如何:分析、分析器和分析代码。
Copyright © The Qt Company Ltd. and other contributors. 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.