Good evening,
I write some data into a file with QDataStream.
out << quint32(magic);
out << qint32(version);
for (int i = 0; i < data.size(); i++)
{
out << data[i].a;
out << data[i].b;
...
out << endl;
}
QDataStream out(&file);
out << quint32(magic);
out << qint32(version);
out.setVersion(QDataStream::Qt_4_8);
for (int i = 0; i < data.size(); i++)
{
out << data[i].a;
out << data[i].b;
...
out << endl;
}
To copy to clipboard, switch view to plain text mode
Now, when reading the file from the same program; it works flawlessly.
QFile file(PATH
+ filename
);
return;
in >> check_magic;
if (check_magic != magic)
return false;
in >> check_version;
if (check_version != version)
return false;
for (int i = o; i < data.size(); i++)
{
in >> data[i].a;
...
in.skipRawData(1); // otherwise the newline makes it messy
}
QFile file(PATH + filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QDataStream in(&file);
in >> check_magic;
if (check_magic != magic)
return false;
in >> check_version;
if (check_version != version)
return false;
in.setVersion(QDataStream::Qt_4_8);
for (int i = o; i < data.size(); i++)
{
in >> data[i].a;
...
in.skipRawData(1); // otherwise the newline makes it messy
}
To copy to clipboard, switch view to plain text mode
When I want to read the file from another program; it stops after the first iteration.
I placed a while(!(file.atEnd()) into my other program, to see how far it comes,
and it stops right after the endline.
I do not understand how that is possible, I use the same code for reading in both programs.
Bookmarks