
Originally Posted by
wysota
Why reset the file at all? Can't you continue reading from the place where you stopped?
I'm not sure i can since i get the "unexpected end of file"-error when i don't reset. The same is true even if i reset the file or close and reopen it. The only way around this i've found is to create a new streamReader-derived object AND reset the QIODevice:
Parser typeCheck; // type checker!
FileType type = typeCheck.getType(&file);
file.reset();
if (type == TypeA){
Parser reader; // actual reading of the file
if (!reader.read(&file)){
cout << "uh oh." << endl;
}
}else{
cout << "bad file type." << endl;
}
file.close();
QFile file(fileName);
file.open(QFile::ReadOnly | QFile::Text);
Parser typeCheck; // type checker!
FileType type = typeCheck.getType(&file);
file.reset();
if (type == TypeA){
Parser reader; // actual reading of the file
if (!reader.read(&file)){
cout << "uh oh." << endl;
}
}else{
cout << "bad file type." << endl;
}
file.close();
To copy to clipboard, switch view to plain text mode
Correct me if i'm wrong but this feels like a bug. According to the documentation, QXmlStreamReader::setDevice() is supposed to reset the reader's internal state. If that were true, then doing reset() on the IODevice and resetting the reader's device should work.
Bookmarks