psantofe
8th September 2010, 15:46
In my app I have to save data in an external binary file (I choose QDataStream class); in particular, I have array of 20 items arranged in 100 memories. Like a bidimensional array, in which I would write o read data starting not necessarily from the begin of file.
The following is the Read() function I'm developing:
void prova12::Read()
{
QString miodato[230]; // array based on QString class
QFile DataStore("store.dat"); // the external binary file to be read is: store.dat
DataStore.open(QIODevice::ReadOnly; // file open in readonly mode
QDataStream in(&DataStore); // datastream is read
for(index = 0; index < 230; index++)
in >> miodato[index]; // the first 230 data in store.dat are saved in "miodato" array
}
From the Qt help, I found:
bool QIODevice::seek(qint64 pos)
It seems to be the solution to my problem, when I want to start my reading from 3rd data; the following is my trial:
void prova12::Read()
{
QString miodato[230];
QFile DataStore("store.dat");
DataStore.open(QIODevice::ReadOnly);
QDataStream in(&DataStore);
/****************/
DataStore.seek(3); // Start to read from 3rd data
/****************/
for(index = 0; index < 230; index++)
in >> miodato[index];
}
But, unfortunately, it doesn't work.
Is there anybody that already use these instructions or understand what's my error?
Thanks
Paolo
The following is the Read() function I'm developing:
void prova12::Read()
{
QString miodato[230]; // array based on QString class
QFile DataStore("store.dat"); // the external binary file to be read is: store.dat
DataStore.open(QIODevice::ReadOnly; // file open in readonly mode
QDataStream in(&DataStore); // datastream is read
for(index = 0; index < 230; index++)
in >> miodato[index]; // the first 230 data in store.dat are saved in "miodato" array
}
From the Qt help, I found:
bool QIODevice::seek(qint64 pos)
It seems to be the solution to my problem, when I want to start my reading from 3rd data; the following is my trial:
void prova12::Read()
{
QString miodato[230];
QFile DataStore("store.dat");
DataStore.open(QIODevice::ReadOnly);
QDataStream in(&DataStore);
/****************/
DataStore.seek(3); // Start to read from 3rd data
/****************/
for(index = 0; index < 230; index++)
in >> miodato[index];
}
But, unfortunately, it doesn't work.
Is there anybody that already use these instructions or understand what's my error?
Thanks
Paolo