QtCreator 能够经过 Clang-Tidy 和 CLazy 对你的代码进行静态检查node
打开你的工程,点击Analyze -> Clang-Tidy and CLazyless
选择你想分析的 cpp, 而后能够点下方 Filter 旁边的 Apply Fixits 按钮修复ide
这里并不想对 static analyze 展开太多,想具体了解的能够看别人的文章,好比函数
Qt:在QtCreator中使用Clang-Tidy和Clazy检查C++代码质量 - Jason’s home - CSDN博客ui
【不要使用一连串的 arg().arg().arg() 了】spa
QString("%1 %2").arg(a).arg(b); // Bad
QString("%1 %2").arg(a, b); // one less temporary heap allocation
【多使用右值引用,能够经过 std::move 将参数转化为右值引用】.net
ChartWidget::ChartWidget(QWidget *parent,QList<int> list) : QWidget(parent), l(list), delt(1.0)
{
} // Bad
ChartWidget::ChartWidget(QWidget *parent,QList<int> list) : QWidget(parent), l(std::move(list)), delt(1.0)
{
} // performance unnecessary value param
【定义函数时,多使用 const &】code
void LogData::setupMatrixCam2Veh(QString table_string) // Bad
void LogData::setupMatrixCam2Veh(const QString& table_string)
// performance unnecessary value param
【不要忘记初始化类的变量,在头文件的变量旁添加 {} 就能够了】orm
QToolButton *resetButton; // Bad
QToolButton *resetButton{}; // cppcoreguidelines pro type member init
【多用auto关键字,尽可能使用更现代化的方式来 new】blog
QHBoxLayout *hl = new QHBoxLayout; // Bad
auto hl = new QHBoxLayout; // modernize use auto
⑥ to be continued...
https://zhuanlan.zhihu.com/p/51791350