The QColor ctor taking ints is cheaper than the one taking string literals [clazy-qcolor

QtCreator警告:The QColor ctor taking ints is cheaper than the one taking string literals [clazy-qcolor-from-literal]

产生原因:

QColor("#ffcccc");

这种方式不推荐,会产生临时的QString

改成下列方式不报警告:

QColor c("#000000"); 改为 QColor c(0, 0, 0) ;

c.setNamedColor("#001122"); 改为 c = QColor(0, 0x11, 0x22) ;

翻译来源:

https://github.com/KDE/clazy/blob/1.11/docs/checks/README-qcolor-from-literal.md

另外一个警告:

Q_PROPERTY should have either NOTIFY or CONSTANT [clazy-qproperty-without-notify]

修改前:
Q_PROPERTY(int RotateAngle READ RotateAngle WRITE setRotateAngle)

报错:
 Q_PROPERTY should have either NOTIFY or CONSTANT [clazy-qproperty-without-notify]


修改后:
Q_PROPERTY(int RotateAngle READ RotateAngle WRITE setRotateAngle NOTIFY RotateAngleChanged)

signals:
    void RotateAngleChanged(const int &rotateAngle);
    
    
然后在setRotateAngle()函数中,
emit RotateAngleChanged(angle);

你可能感兴趣的:(QT实用笔记,QtCreator警告)