Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QString converts \r\n to \n while assigning text to QText Edit.

QString converts \r\n to \n while assigning text to QText Edit.

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 265 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ayush Gupta
    wrote on last edited by
    #1

    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 ?

    JKSHJ 1 Reply Last reply
    0
    • A Ayush Gupta

      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 ?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by JKSH
      #2

      @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.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      5

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved