Serializing my custom class in Qt

随声附和 提交于 2019-12-02 22:38:57
Kamil Klimek

You must make id and Name as Q_PROPERTY to handle it with metaObject property system:

class student : public Base
{
    Q_OBJECT // Q_OBJECT macro will take care of generating proper metaObject for your class
    Q_PROPERTY(int id READ getId WRITE setId)
    Q_PROPERTY(QString Name READ getName WRITE setName)
public:
    student();
    int getId() const { return id; }
    void setId(int newId) { id = newId; }
    QString getName() const { return Name; }
    void setName(const QString &newName) { Name = newName; }

private:
    int id;
    QString Name;
};

Now properties should be handled in proper way.

See http://doc.qt.io/qt-5/properties.html for detailed information.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!