Originally Posted by
Lesiok
In the first step You saved to a file memory area with size 500 * sizeof (double) from the array g1. Exactly the same load the file into memory and have data array double [500]. Do not close the file between subsequent readings.
Thanks. I used this:
void read()
{
QFile g1f, g2f, of, chf, namef;
double g1[500];
double g2[500];
double ofse[500];
int ch[500];
g1f.setFileName("oneFile.th");
if(!g1f.
open(QFile::ReadOnly)) {
qDebug()<<"can not open to read";
}
g1f.read((char*)g1, (500)*sizeof(double));
g2f.setFileName("oneFile.th");
if(!g2f.
open(QFile::Append)) {
qDebug()<<"can not open to read";
}
g2f.read((char*)g2, (500)*sizeof(double));
of.setFileName("oneFile.th");
if(!of.
open(QFile::Append)) {
qDebug()<<"can not open to read";
}
of.read((char*)ofse, (500)*sizeof(double));
chf.setFileName("oneFile.th");
if(!chf.
open(QFile::Append)) {
qDebug()<<"can not open to read";
}
chf.read((char*)ch, (500)*sizeof(int));
namef.setFileName("oneFile.th");
if(!namef.
open(QFile::Append)) {
qDebug()<<"can not open to write";
}
df >> names;
namef.close();
for(int y=0; y<500; y++)
qDebug()<<ch[y];
}
void read()
{
QFile g1f, g2f, of, chf, namef;
double g1[500];
double g2[500];
double ofse[500];
int ch[500];
QStringList names;
g1f.setFileName("oneFile.th");
if(!g1f.open(QFile::ReadOnly))
{
qDebug()<<"can not open to read";
}
g1f.read((char*)g1, (500)*sizeof(double));
g2f.setFileName("oneFile.th");
if(!g2f.open(QFile::Append))
{
qDebug()<<"can not open to read";
}
g2f.read((char*)g2, (500)*sizeof(double));
of.setFileName("oneFile.th");
if(!of.open(QFile::Append))
{
qDebug()<<"can not open to read";
}
of.read((char*)ofse, (500)*sizeof(double));
chf.setFileName("oneFile.th");
if(!chf.open(QFile::Append))
{
qDebug()<<"can not open to read";
}
chf.read((char*)ch, (500)*sizeof(int));
namef.setFileName("oneFile.th");
if(!namef.open(QFile::Append))
{
qDebug()<<"can not open to write";
}
QDataStream df(&namef);
df >> names;
namef.close();
for(int y=0; y<500; y++)
qDebug()<<ch[y];
}
To copy to clipboard, switch view to plain text mode
now i have 2 issues. it gives me this when i want to read:
QIODevice::read (QFile, "oneFile.th"): WriteOnly device
QIODevice::read (QFile, "oneFile.th"): WriteOnly device
QIODevice::read (QFile, "oneFile.th"): WriteOnly device
QIODevice::read (QFile, "oneFile.th"): WriteOnly device
and for example in "int ch[500]", after reading, ch[499] must equal to 499 but it equals to 497! what is wrong?
Bookmarks