Results 1 to 5 of 5

Thread: QFile/QIODevice: how to get platform end-of-line terminator?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QFile/QIODevice: how to get platform end-of-line terminator?

    Hello,
    I need to read a text file in binary mode (don't ask me why...). Is there any way I can get the end-of-line terminator for the current platform?

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile/QIODevice: how to get platform end-of-line terminator?

    in my reckoning, \n would would on all platforms, its \n for linux and mac, \r\n for windows, but qt replaces that with \n

  3. #3
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFile/QIODevice: how to get platform end-of-line terminator?

    Quote Originally Posted by talk2amulya View Post
    in my reckoning, \n would would on all platforms, its \n for linux and mac, \r\n for windows, but qt replaces that with \n
    That's ok when you are opening the file in text mode. In non-text mode, readLine returns "hello\r\n" on windows and "hello\n" on linux, so the following code will work not work on Linux:

    Qt Code:
    1. if (line == "\r\n")
    2. processEmptyLine(line);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    May 2009
    Posts
    61
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFile/QIODevice: how to get platform end-of-line terminator?

    You are reading a file binary to process then each "line"?

    It does not really help you to decide that you on windows have \r\n - still someone can copy/mail a unix file. What about split the buffer by \n into a QStringList and replace \r by ""?
    Or use QString::simplified to check emptyness?

  5. The following user says thank you to auba for this useful post:

    mattc (17th May 2009)

  6. #5
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFile/QIODevice: how to get platform end-of-line terminator?

    Quote Originally Posted by auba View Post
    It does not really help you to decide that you on windows have \r\n - still someone can copy/mail a unix file.
    Good point, I am going for the simplified()/trimmed() approach.

Similar Threads

  1. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  2. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  3. Crash handler on Win32
    By niko in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 19:41
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

Tags for this Thread

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.