Results 1 to 4 of 4

Thread: qtextstream & qstring

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default qtextstream & qstring

    Qt Code:
    1. text ="left\n";
    2. text =text +"right\n";
    3. QFile f(file);
    4. f.open(IO_WriteOnly);
    5. QTextStream xstrm(&f);
    6. xstrm << text;
    7. f.close();
    To copy to clipboard, switch view to plain text mode 
    I thought that this code produce a file so:
    Qt Code:
    1. left
    2. right
    To copy to clipboard, switch view to plain text mode 
    Instead:
    Qt Code:
    1. leftright
    To copy to clipboard, switch view to plain text mode 
    how can I do? thanks.
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qtextstream & qstring

    it seems you forget a flag in the open method of your file.

    in Qt4 the flag is QIODevice::Text, so in Qt3 it should be something like IO_Text

    on Windows, line breaks aren't only "\n" but actually "\r\n"
    Current Qt projects : QCodeEdit, RotiDeCode

  3. The following user says thank you to fullmetalcoder for this useful post:

    mickey (24th February 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qtextstream & qstring

    One should use endl() to write a newline to the stream instead of using \n.

  5. #4
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qtextstream & qstring

    Quote Originally Posted by wysota
    One should use endl() to write a newline to the stream instead of using \n.
    Because windows consider a new line to be "\n\r" , they just can't figure out that computers are not typewriters anymore

Similar Threads

  1. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 16:26
  2. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47
  3. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  4. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:10
  5. [SOLVED] Widget plugin ... how to ?
    By yellowmat in forum Newbie
    Replies: 10
    Last Post: 29th January 2006, 20:41

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.