文章目录
- Missing reference in range-for with non trivial type (QString) [clazy-range-loop]
- Slots named on_foo_bar are error prone [clazy-connect-by-name]
- Call to virtual method 'FlowLayout::takeAt' during destruction bypasses virtual dispatch [clang-analyzer-optin.cplusplus.VirtualCall]
- non-POD static (QString) [clazy-non-pod-global-static]
静态分析代码工具
Missing reference in range-for with non trivial type (QString) [clazy-range-loop]
for 循环范围中(QString)[clazy range loop]的的范围中缺少引用

本质 QString imagePath 是个临时变量,每次for都要申请内存再销毁是没有必要的
//改后
void TextureLibrary::generateTexture(const QList &imagePathList)
{if (!m_glTextureList.isEmpty()){this->clearTexture();}for (auto &imagePath : imagePathList){this->appendGlTexture(imagePath);}
}
Slots named on_foo_bar are error prone [clazy-connect-by-name]
.ui 默认生成的槽就会报,不用管它
Call to virtual method ‘FlowLayout::takeAt’ during destruction bypasses virtual dispatch [clang-analyzer-optin.cplusplus.VirtualCall]
在类的构造和虚构中调用虚函数需要加类名

//改后
FlowLayout::~FlowLayout()
{QLayoutItem *item;while ((item = FlowLayout::takeAt(0)))delete item;
}
non-POD static (QString) [clazy-non-pod-global-static]

《Effective C++》
条款02 对于单纯常量,最好以const对象或enum替换#define;对于形似函数的宏,最好改用inline函数替换#define
Qt 中建议 Q_GLOBAL_STATIC , 我个人喜欢写到类的静态成员变量中
class A{
public:static QString _path;
};
QString A::_path = "xxx";