PDA

View Full Version : Unix or PC linefeeds in textfiles



bnilsson
31st July 2009, 19:51
I am saving my text from a QPlaintTextEdit like this:
QTextStream out(&file);
out << fTextView->toPlainText();
Now if I want to control wether the file should be written in Unix or PC text format, are there any "higher-level" tools or settings to do this, or do I just load the text into a QString and search and modify \n to \r\n or vice versa by my own code?

shentian
31st July 2009, 21:53
If you open the file using QIODevice::Text, the line breaks are handled platform-dependent:


When reading, the end-of-line terminators are translated to '\n'. When writing, the end-of-line terminators are translated to the local encoding, for example '\r\n' for Win32.

If you want to write Unix eols on Windows or vice versa, you'll have to do it yourself.

bnilsson
31st July 2009, 22:37
Ok, thanks.