PDA

View Full Version : QTextStream to open file once but read multiple times



timmu
3rd January 2012, 11:09
Hi,

I'd like to open file once but read it several times from start to end. Do you need a new QTextStream for every read (as shown below), or is it possible to reset the the stream? I have tried flush() and reset() but they won't do it.



char mystring[100]; char mystring2[100];
QFile infile(""myfile.txt"); if(!infile.open(QIODevice::ReadOnly | QIODevice::Text)) {exit(1);}

QTextStream in_stream(&infile);
QTextStream in_stream2(&infile);
in_stream >> mystring;
in_stream2 >> mysting2;

infile.close();

wysota
3rd January 2012, 11:25
in_stream.seek(0)