PDA

View Full Version : Mac line breaks



timmu
8th August 2012, 11:25
Hi,

My input file (a csv text file) was created with a Mac. Since Mac uses different line breaks my application which runs in Windows or Linux cannot properly read the file line by line (it reads the entire row). I know this used to be a bug in Qt. Has it been fixed? Can I now read Mac files (with Mac line braks) if my program runs on windows. This is how I do it:



QFile infile(Filename); if(!infile.open(QIODevice::ReadOnly | QIODevice::Text)) {exit(1);}
QTextStream in_stream(&infile);

while(!in_stream.atEnd())
{
QString row = in_stream.readLine();
}

infile.close();

ChrisW67
9th August 2012, 06:03
You could have answered this question for yourself in less time than it took to post. Feed it an ancient Mac file with CR line endings and see what you get. Alternatively, look at the QTextStream source where you will see that it looks for the single character \n optionally preceded by \r.

I would not consider this a bug given that the documentation specifically mentions only "\n" and "\r\n" as end-of-line markers, and Qt is not supported on Mac OS 9 or earlier. Mac OS X uses LF line endings so this should not be an issue for files from those systems.

None of this stops you from handling such files, but you have to do more of the work.