c++qtreadlineqtextstream

QT reading file line by line


I need to read the contents of a file line by line.

Sample.txt:

#define <tabspace> temp <tabspace> 10

Code:

QFile file("D:\Sample.txt");
QTextStream in(&file);
QString str_Line = in.readLine();

str_Line contains #definetemp10

How to read the line with including the tab spaces? can any one please help me out?


Solution

  • Combine the multiple whitespaces into a single white space. Use QString::simplified() or QString::trimmed().

    In your code add the below line,

    QString str_Line = in.readLine();
    str_Line.trimmed();//
    str_Line.simplified();//