lecture erronée (QDataSream,QList<QVariant>, struct)
Bonjour. :roll:
J'ai un petit problème de lecture dans un fichier.
Mon fichier binaire stock une liste de QVariant : QList< QVariant >
Mes QVaraint sont de type structure : typedef struct FICHE{....}
Pour résumer : Je n'ai aucune erreur de compilation , ni de warning
Je défini ma struct dans un fichier.h globalement comme ceci:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
....
#include <QVariant>
typedef struct FICHE_HTable{
char tablename[15];
char players[15];
}FICHE_HTable;
Q_DECLARE_METATYPE(FICHE_HTable);
... |
Dans ma Fonction WriteToFile :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
....
QList< QVariant > tables = mon_modele1->getListofTable();
/////// Je test si une valeur dans ma fiche est correct.
QVariant tbli;
for(int i=0;i<tables.size();i++){ // Le nobre d'engresitrement est CORRECT!!!
tbli= tables.value(i);
FICHE_HTable fich = tbli.value<FICHE_HTable>();
QMessageBox::information(&dialog, "info", fich.tablename); //Ma valeur est CORRECT!!!
}
///////
QDataStream out(&file);
out << tables; |
Dans ma Fonction ReadToFile :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
QList< QVariant > tables; //= mon_modele1->getListofTable();???
QDataStream in(&file);
in >> tables; // Le nobre d'engresitrement est CORRECT!!!
if (tables.isEmpty()) {
QMessageBox::information(&dialog, tr("No contacts in file"),
tr("The file you are attempting to open contains no tables."));
} else {
for (int i=0; i<tables.size(); ++i) { // Le nobre d'engresitrement est CORRECT!!!
QVariant var = tables.at(i);
FICHE_HTable fich = var.value<FICHE_HTable>();
QMessageBox::information(&dialog, "information box",fich.tablename); // Les valeurs de ma fich sont ERRONEE!!!
addrowEntry(fiche.tablename, fiche.player, ); // Mon modele affiche également les meme valeurs ERRONEE de ma fiche
} |
Cela fais 2 jours que j'essaye de récupérer des valeurs sous forme d'une fiche , pas moyen. j'ai suivi pourtant l'example de L'ADRESSE_BOOK et d'autre tres intéressant via ce forum.
Je ne vois pas ce qui cloche ...
Ou est l'erreur??? :calim2: