I'm trying to make .obj parser for one project.
I have ObjLoader class with loaddata method. And it reads file line by line and parse it as I need.
QFile file(sourceFolder+ QString("/") +filename);
file.open(QIODevice::ReadOnly);
QTextStream textStream(&file);
QString currentString;
while (!textStream.atEnd())
{
currentString = textStream.readLine();
//Some code here without closing file(I doublechecked this)
}
file.close()
It reads first 600 strings well, but then unexpectedly stops.
It happens on these strings:
v 3.956570 0.532126 0.300000
v 3.958734 0.593226 -0.300000
v 3.958731 0.593220 0.300000
vn 0.0000 -0.0000 1.0000
vn 0.0000 0.0000 -1.0000
vn 0.4852 -0.8744 0.0000
But when I tried
std::cerr "<<" currentString.toStdString() "<<" "\n";
(Sorry, don't know how to write this normally with stackoverflow formatting)
for these strings by using index "int i" which increments each time in the loop, it gives only this:
v 3.956570 0.532126 0.300000
v 3.958734 0.593226 -0.300000
v 3.958731 0.593220 0.300000
v
And in this point it stops reading file without any errors. It looks like the file in memory ends here. But it is only the 601-st string, when the file has 1100+ of them.
I checked the file in the text editor for unprintable symbols, but here is not any of them in this part.
Each time when I start debugging of this code it do the same thing - the same string stops the reading at the same symbol. Why can it happen?
QByteArray
fromQFile
intead of usingQTextStream
, because using wrong encoding can lead to funny things... – hyde