PDA

View Full Version : NotePad and WordPad (why)



baray98
29th July 2008, 21:23
I was trying to save some text from my QTextBrowser to a file like below



QString strFile = QFileDialog::getSaveFileName(this);
if (!strFile.isEmpty())
{
QFile myFile(strFile);
if (myFile.open(QIODevice::WriteOnly))
myFile.write(text().toUtf8());

}


now when i look at my saved file in NotePad its one big long line but in the WordPad its okey meaning lines (newlines) are the same as what i saw in my QTextBrowser.

Does it mean that there a special thingy for notepad?

baray98

P.S.
I also tried using QTextStream to save it....

kghose
29th July 2008, 22:41
Hi,

Notepad can not do unix style newlines (\n) it needs dos/windows style which is (I think) '\r\n'. Wordpad on the other hand can do both

-K

KaptainKarl
29th July 2008, 22:48
If you use the QIODevice mode Text rather than WriteOnly, then the end of line character will be translated according to the local encoding, for example "\r\n" for Win32.

Karl