Hello
I experience issues when running my application
I have personnal object (ChannelObjectSerializable) which I want to save status.
Here is part of the code which will help :
After the sync() :
QVariant::load: unable to load type 257.
QVariant::save: unable to save type 257.
QVariant::load: unable to load type 257.
#####################
# Channel :
# #
# #
# #
# #
# #
#####################
QVariant::load: unable to load type 257.
QVariant::save: unable to save type 257.
QVariant::load: unable to load type 257.
#####################
# Channel :
# #
# #
# #
# #
# #
#####################
To copy to clipboard, switch view to plain text mode
Avec :
ChannelObjectSerilizable.h
private:
};
Q_DECLARE_METATYPE(ChannelObjectSerializable)
private:
friend QDataStream & operator << (QDataStream &, const ChannelObjectSerializable &);
friend QDataStream & operator >> (QDataStream &, ChannelObjectSerializable &);
};
Q_DECLARE_METATYPE(ChannelObjectSerializable)
QDataStream & operator << (QDataStream & out, const ChannelObjectSerializable & Valeur);
QDataStream & operator >> (QDataStream & in, ChannelObjectSerializable & Valeur);
To copy to clipboard, switch view to plain text mode
ChannelObjectSerializable.cpp :
void ChannelObjectSerializable::initChannelSystem()
{
qRegisterMetaTypeStreamOperators("ChannelObject");
qMetaTypeId();
}
{
out << tmp.fromStdString(Valeur.nom)
<< tmp.fromStdString(Valeur.lastUpdate)
<< tmp.fromStdString(Valeur.description)
<< tmp.fromStdString(Valeur.lien)
<< tmp.fromStdString(Valeur.link);
return out;
}
{
in >> tmp;
Valeur.nom = tmp.toStdString();
in >> tmp;
Valeur.lastUpdate = tmp.toStdString();
in >> tmp;
Valeur.description = tmp.toStdString();
in >> tmp;
Valeur.lien = tmp.toStdString();
in >> tmp;
Valeur.link = tmp.toStdString();
return in;
}
void ChannelObjectSerializable::initChannelSystem()
{
qRegisterMetaTypeStreamOperators("ChannelObject");
qMetaTypeId();
}
QDataStream & operator<<(QDataStream & out, const ChannelObjectSerializable & Valeur)
{
QString tmp;
out << tmp.fromStdString(Valeur.nom)
<< tmp.fromStdString(Valeur.lastUpdate)
<< tmp.fromStdString(Valeur.description)
<< tmp.fromStdString(Valeur.lien)
<< tmp.fromStdString(Valeur.link);
return out;
}
QDataStream & operator>>(QDataStream & in, ChannelObjectSerializable & Valeur)
{
QString tmp;
in >> tmp;
Valeur.nom = tmp.toStdString();
in >> tmp;
Valeur.lastUpdate = tmp.toStdString();
in >> tmp;
Valeur.description = tmp.toStdString();
in >> tmp;
Valeur.lien = tmp.toStdString();
in >> tmp;
Valeur.link = tmp.toStdString();
return in;
}
To copy to clipboard, switch view to plain text mode
main.cpp
ChannelObjectSerializable p = ChannelObjectSerializable(newRSS);
p.initChannelSystem();
fichier_ecrire.setValue("channel", qVariantFromValue(p));
p.printDonnees();
fichier_ecrire.sync();
ChannelObjectSerializable copie;
copie = fichier_lire.value("channel", qVariantFromValue(ChannelObjectSerializable())).value();
copie.printDonnees();
ChannelObjectSerializable p = ChannelObjectSerializable(newRSS);
p.initChannelSystem();
QSettings fichier_ecrire("Test.ini", QSettings::IniFormat);
fichier_ecrire.setValue("channel", qVariantFromValue(p));
p.printDonnees();
fichier_ecrire.sync();
ChannelObjectSerializable copie;
QSettings fichier_lire("Test.ini", QSettings::IniFormat);
copie = fichier_lire.value("channel", qVariantFromValue(ChannelObjectSerializable())).value();
copie.printDonnees();
To copy to clipboard, switch view to plain text mode
After loading the object, it's empty
Bookmarks