0

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?

Anthony Geoghegan
  • 11,533
  • 5
  • 49
  • 56
IPS
  • 81
  • 1
  • 12
  • My output should look like #define temp 10 (i.e) with the tab space – IPS Mar 05 '15 at 06:10
  • I edited the question to better see what is what. If I understood your intent wrong, please edit further! – hyde Mar 05 '15 at 06:24
  • 1
    `readLine` will certainly read and keep spaces. If your output is without them, there's something else going on! Try printing `std_Line.simplify()` and see if it then prints correctly (check the docs to see what it does). – hyde Mar 05 '15 at 06:26
  • Another debugging hint, print `std_Line.toLatin1().toHex()` (and check the docs to see what it does). As it is know, your question does not really have enough details to answer accurately. – hyde Mar 05 '15 at 06:31
  • Thanks for your response. It solved my query.. Simplified returned the hidden white spaces. – IPS Mar 05 '15 at 06:32

1 Answers1

1

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();//