C++ (Qt)struct MyType{ QString data;}; Q_DECLARE_METATYPE(MyType)Q_DECLARE_METATYPE(QList<MyType>)
C++ (Qt)static QDataStream &operator<<(QDataStream &out, const MyType &t){ out << t.data; return out;} static QDataStream &operator>>(QDataStream &in, MyType &t){ in >> t.data; return in;} ... main(){ ... qRegisterMetaTypeStreamOperators<MyType>("MyType"); qRegisterMetaTypeStreamOperators<QList<MyType> >("QList<MyType>"); QSettings sett; ...}
C++ (Qt)struct MyType{ MyType(const QString &d = QString(), int t = 0) : data(d), type(t) {} QString data; int type;}; Q_DECLARE_METATYPE(MyType)Q_DECLARE_METATYPE(QList<MyType>) int main(int argc, char *argv[]){ QCoreApplication::setApplicationName("T2"); QCoreApplication::setOrganizationName("T2"); QCoreApplication ap(argc, argv); qRegisterMetaType<MyType>("MyType"); qRegisterMetaType<QList<MyType> >("QList<MyType>"); MyType t("xxx", 8); QSettings ss; ss.setValue("key", QVariant::fromValue<MyType>(t)); return 0;}
C++ (Qt)static QDataStream &operator<<(QDataStream &out, const MyType &t){ out << t.data; return out;}
static QDataStream &operator<<(QDataStream &out, const _ITEM_s &t){ QByteArray utf; out << t.val1.toUtf8(); out << t.val2.toUtf8(); out << t.val3.toUtf8(); return out;}static QDataStream &operator>>(QDataStream &in, _ITEM_s &t){ QByteArray utf; in >> utf; t.val1 = QString::fromUtf8(utf, -1); in >> utf; t.val2 = QString::fromUtf8(utf, -1); in >> utf; t.val3 = QString::fromUtf8(utf, -1); return in;}