PDA

View Full Version : QTextStream not reading the entire file



ayanda83
18th October 2016, 12:32
I am trying to read a text file line by line. File has got 695 lines of text but for some reason QTextStream only reads up to 501 lines and anything after that is not read. Here is my code below.
void read(QString path1)
{
QFile rfile(path1);

if(!rfile.open(QFile::ReadOnly | QFile::Text))
{
qDebug() << "File did not open" <<endl;
return;
}

QTextStream in(&rfile);
stringList.clear();

while(!rfile.atEnd())
{
QString trwCode = in.readLine(0);
if(trwCode.contains("http://"))
trwCode.remove(0, 7);
else if(trwCode.contains("https://"))
trwCode.remove(0, 8);

qDebug() <<trwCode <<endl;

stringList.append(trwCode);

trwCode.clear();

}

rfile.flush();
rfile.close();
}

Lesiok
18th October 2016, 13:01
Change line 14 to :
while(!in.atEnd())

ayanda83
18th October 2016, 13:16
Lol, it works. thanks