Results 1 to 3 of 3

Thread: Unix or PC linefeeds in textfiles

  1. #1
    Join Date
    Jan 2008
    Posts
    155
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Unix or PC linefeeds in textfiles

    I am saving my text from a QPlaintTextEdit like this:
    Qt Code:
    1. QTextStream out(&file);
    2. out << fTextView->toPlainText();
    To copy to clipboard, switch view to plain text mode 
    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?
    MacOSX user dabbling with Linux and Windows.

  2. #2
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unix or PC linefeeds in textfiles

    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.

  3. #3
    Join Date
    Jan 2008
    Posts
    155
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Unix or PC linefeeds in textfiles

    Ok, thanks.
    MacOSX user dabbling with Linux and Windows.

Similar Threads

  1. Strange problem with events on Unix
    By sukanyarn in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2006, 02:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.