PDA

View Full Version : QFile/QIODevice: how to get platform end-of-line terminator?



mattc
16th May 2009, 18:00
Hello,
I need to read a text file in binary mode (don't ask me why...). Is there any way I can get the end-of-line terminator for the current platform?

talk2amulya
16th May 2009, 19:40
in my reckoning, \n would would on all platforms, its \n for linux and mac, \r\n for windows, but qt replaces that with \n

mattc
16th May 2009, 20:17
in my reckoning, \n would would on all platforms, its \n for linux and mac, \r\n for windows, but qt replaces that with \n

That's ok when you are opening the file in text mode. In non-text mode, readLine returns "hello\r\n" on windows and "hello\n" on linux, so the following code will work not work on Linux:


if (line == "\r\n")
processEmptyLine(line);

auba
17th May 2009, 12:29
You are reading a file binary to process then each "line"? :confused:

It does not really help you to decide that you on windows have \r\n - still someone can copy/mail a unix file. What about split the buffer by \n into a QStringList and replace \r by ""?
Or use QString::simplified to check emptyness?

mattc
17th May 2009, 19:21
It does not really help you to decide that you on windows have \r\n - still someone can copy/mail a unix file.

Good point, I am going for the simplified()/trimmed() approach.