Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i store Custom types in QSettings?

Tags:

qt

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");
like image 422
Mr.Tu Avatar asked Dec 31 '25 19:12

Mr.Tu


1 Answers

qRegisterMetaTypeStreamOperators is a function, not a macro.

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

like image 101
Tim Meyer Avatar answered Jan 03 '26 12:01

Tim Meyer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!