QString converts \r\n to \n while assigning text to QText Edit.
-
I have some file contents where some line endings ends with \r\n and some line endings with \n.
When I am assigning string class data to QString than QString class converts all \r\n to \n.I am doing this since I need to set the file data in QTextEdit for editing. Is there any way I can set the data in QTextEdit without \r\n changed to \n.
And when I edit the data in QTextEdit and get the data from it the line endings with \r\n will be same as original ?
-
@Ayush-Gupta said in QString converts \r\n to \n while assigning text to QText Edit.:
When I am assigning string class data to QString than QString class converts all \r\n to \n
This is expected. Qt uses
\n
as the line ending in memory for all text on all platforms.When Qt writes text files, it automatically converts all line endings to
\r\n
on Windows.Is there any way I can set the data in QTextEdit without \r\n changed to \n
No.
To preserve the
\r\n
you must keep your data as a byte array and avoid converting it into a text string.QTextEdit
only operates on text strings.One possible solution is to keep track yourself which lines use what line endings, and restore the original endings when you have finished editing.