Results 1 to 2 of 2

Thread: Mac line breaks

  1. #1
    Join Date
    Aug 2009
    Posts
    122
    Thanks
    74
    Qt products
    Qt4
    Platforms
    Windows

    Default Mac line breaks

    Hi,

    My input file (a csv text file) was created with a Mac. Since Mac uses different line breaks my application which runs in Windows or Linux cannot properly read the file line by line (it reads the entire row). I know this used to be a bug in Qt. Has it been fixed? Can I now read Mac files (with Mac line braks) if my program runs on windows. This is how I do it:

    Qt Code:
    1. QFile infile(Filename); if(!infile.open(QIODevice::ReadOnly | QIODevice::Text)) {exit(1);}
    2. QTextStream in_stream(&infile);
    3.  
    4. while(!in_stream.atEnd())
    5. {
    6. QString row = in_stream.readLine();
    7. }
    8.  
    9. infile.close();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Mac line breaks

    You could have answered this question for yourself in less time than it took to post. Feed it an ancient Mac file with CR line endings and see what you get. Alternatively, look at the QTextStream source where you will see that it looks for the single character \n optionally preceded by \r.

    I would not consider this a bug given that the documentation specifically mentions only "\n" and "\r\n" as end-of-line markers, and Qt is not supported on Mac OS 9 or earlier. Mac OS X uses LF line endings so this should not be an issue for files from those systems.

    None of this stops you from handling such files, but you have to do more of the work.

Similar Threads

  1. Input breaks my program all of a sudden?
    By getajob92 in forum Newbie
    Replies: 0
    Last Post: 18th April 2012, 17:54
  2. Remove line breaks in QDomDocument
    By estanisgeyer in forum Qt Programming
    Replies: 0
    Last Post: 17th December 2010, 12:39
  3. Qt4 'breaks' command line program
    By kachofool in forum Newbie
    Replies: 7
    Last Post: 13th November 2009, 21:56
  4. lupdate breaks files
    By icwiener in forum Qt Tools
    Replies: 2
    Last Post: 17th May 2009, 03:01
  5. Computing page breaks
    By js in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2007, 14:56

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.