class ReadFile {
public:
void init();
QList<double> getData();
private:
QFile file;
QDataStream read;
double bufferFloat;
quint32 bufferInteger
}
init() が呼び出されると、ファイルが開かれ、データが開始する場所にナビゲートされる必要があるという考え方になりました。これで、getData() が呼び出されるたびに、バイトのチャンクがファイルから読み取られる必要があります。
擬似コードは次のようになります。
void ReadFile::init()
{
file.setFileName("...");
file.open(QIODevice::ReadOnly);
QDataStream read(&file);
// This chunk does some magic to find correct location by applying
// a readout (read >> bufferInteger) and check the result
// I can verify that at this point, if doing a readout (read >> bufferFloat)
// I get good data (i.e. corresponding to the file).
}
と
QList<double> ReadFile::getData()
{
// Doing a (read >> bufferFloat) at this point will result in zeros.
}
read
ininit
がローカルで宣言されているため、これが発生する理由を理解しています。getData
しかし、中断したところから再開できるように、データ ストリームをどのように割り当てればよいinit
でしょうか。そして、次getData
は前の中断したところから再開できます。呼び出しシーケンスは次のようになります。
ReadFile file();
file.init();
file.readData();
file.readData();
file.readData();
file.readData();
//etc...