当前位置: 首页 > news >正文

Qt中QObject禁止operator=重载

Qt中QObject禁止operator=重载

比如我设计一个类(直接从项目中粘过来了,主要看有没有继承自QObject)

点击查看代码
class RecipePointConfig:QObject
{
Q_Object
public:explicit RecipePointConfig(QObject*parent=nullptr);// JSON序列化QJsonObject toJson() const;bool fromJson(const QJsonObject& obj);
public:QString m_recipeName;           // 工艺名称QString m_description;          // 工艺描述QVector<RecipePoint> m_points;  // 工作点位列表
};
因为RecipePointConfig继承了QObject,所以我们**没有办法直接对这个类进行赋值操作**
点击查看代码
RecipePointConfig a;
RecipePointConfig b;
a=b;
而且**也不允许自己重载operator=()** 所以像这样的纯数据类,只要不定义指针,或者能保证正确delete掉,就可以不用继承自QObject,不需要用对象树来管理释放