3

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");
4

1 回答 1

4

qRegisterMetaTypeStreamOperators is a function, not a macro.

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

于 2012-07-13T08:18:04.583 回答