Mr.Tu
Mr.Tu

Reputation: 2733

How can i store Custom types in QSettings?

From API docs:

Custom types registered using qRegisterMetaType() and qRegisterMetaTypeStreamOperators() can be stored using QSettings.

How can I do that? I get the error:

too few template-parameter-lists at qRegisterMetaTypeStreamOperators

My code:

class LineUser {
public:
    int uId;
    QString passwd;
    qint8 statusType;
};

Q_DECLARE_METATYPE(LineUser)
QDataStream &operator<<(QDataStream &out, const LineUser &myObj) {
    out<<myObj.uId<<myObj.passwd<<myObj.statusType;
    return out;
}
QDataStream &operator>>(QDataStream &in, LineUser &myObj) {
    in>>myObj.uId>>myObj.passwd>>myObj.statusType;
    return in;
}
qRegisterMetaTypeStreamOperators<LineUser>("LineUser");

Upvotes: 3

Views: 2019

Answers (1)

Tim Meyer
Tim Meyer

Reputation: 12600

qRegisterMetaTypeStreamOperators is a function, not a macro.

You need to call it from a .cpp file, e.g. in your main() method

Upvotes: 4

Related Questions