[Qt-interest] QTextDocument and "\r\n" new-lines
Constantin Makshin
cmakshin at gmail.com
Wed Mar 17 23:20:24 CET 2010
Have you tried to open the file with QIODevice::Text flag set? I.e.
something like
QTextDocument doc;
...
QFile file("foo.txt");
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream stream(&file);
stream << doc.toPlainText();
file.close();
}
...
On Wed, 17 Mar 2010 15:39:42 +0300, Qt Quest <qt.quest at yahoo.com> wrote:
> Anyone has an idea how to keep DOS/Windows text format - "\r\n" as new
> lines?
> I'm using QPlainTextEdit. When loading a DOS file, the text document
> changes it to a 1-char newline text, so saving it to a file creates a
> UNIX text format.
> Any workarounds?
> Thanks!
>
> --- On Thu, 3/11/10, Qt Quest <qt.quest at yahoo.com> wrote:
>
> From: Qt Quest <qt.quest at yahoo.com>
> Subject: QTextDocument and "\r\n" new-lines
> To: qt-interest at trolltech.com
> Date: Thursday, March 11, 2010, 7:28 AM
>
> Hi all,
>
> Currently, QTextDocument treats "\r\n" as "\n" when setting the document
> text.
> The problem with this behavior is that the Qt would report the next line
> as starting one character earlier (and line 100: 100 characters
> earlier). This messes with the indexes which are computed with the file
> on the hard disk
> Also, writing the file again will change the file format from dos to
> unix.
>
> I tried changing QTextCursor::insertText line 1330:
> if (ch == QLatin1Char('\r')
> && (i + 1) < text.length()
> && text.at(i + 1) == QLatin1Char('\n')) {
> continue;
> //++i;
> //ch = text.at(i);
> }
>
> which solves the indexes problem, but now the
> visible-text-symbol-of-newline is shown (like in word processors). Any
> way to work around it?
>
> Thank you!
--
Constantin Makshin
More information about the Qt-interest-old
mailing list