After open a text file, I read all with:
QFile MyFile("myfile.txt);
MyFile.open(QIODevice::ReadOnly);
QTextStream in (&MyFile);
while (!in.atEnd())
{
(do something);
}
MyFile.close();
When I recall my function, the "while" loop appears as at its end, so none of the function placed in it are done. Is it a way to re-initialize "atEnd", in such a way I can re-enter in the "while" loop?
QTextStream has a seek function, allowing the position of the stream to be set. Calling
in.seek(0)
will set the stream to the beginning of the file.
However, if the code in the question is in a function, the QFile and QTextStream should be deleted when the function exists, since they're created on the stack, so there may something else going on here, which the question is omitting.