Results 1 to 7 of 7

Thread: QTextStream not adding new line

  1. #1
    Join Date
    Sep 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default QTextStream not adding new line

    I am trying to write to a buffer and then to the screen, i am using

    Qt Code:
    1. ]buffer << j.value() << "|" << j.key() << "\r\n";
    To copy to clipboard, switch view to plain text mode 

    i have tried

    "\n"
    '\n'
    '\r\n'
    << endl

    and none of them will add a new line..any ideas?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: QTextStream not adding new line

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. QString str;
    6. QTextStream stream(&str);
    7. stream << "foo" << "\n" << "bar";
    8. QLabel l(str);
    9. l.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    works as expected. If it also did for you, then anything other in your code is wrong...

  3. #3
    Join Date
    Sep 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QTextStream not adding new line

    what else would be wrong in my code that would effect simply adding a new line

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: QTextStream not adding new line

    Does it work for you or not? and where do you display the text? Maybe there new lines are ignored.

    EDIT: Or do you convert it afterwards in some way?

  5. #5
    Join Date
    Sep 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QTextStream not adding new line

    Qt Code:
    1. QString message;
    2. QTextStream buf(&message);
    3. int count =0 ;
    4. QMapIterator<int, QString> i(sortedFound);
    5. i.toBack();
    6. buf << "FOUND" << endl;
    7. while (i.hasPrevious() && count < n)
    8. {
    9. i.previous();
    10. buf << i.value() << "|" << i.key() << "\r\n";
    11. count++;
    12. }
    13. QTextEdit label2(message);
    14. label2.show();
    To copy to clipboard, switch view to plain text mode 

    is what i have that doesnt work

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: QTextStream not adding new line

    Here we go! By passing the text to the ctor QTextEdit interprets it as HTML. Therefore you see no newline. Use QTextEdit::setText() or use QPlainTextEdit if you don't need HTML.

  7. #7
    Join Date
    Sep 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QTextStream not adding new line

    YES! problem solved, thank you * 100000

Similar Threads

  1. QTextStream : Remove a Line?
    By kaydknight in forum Qt Programming
    Replies: 7
    Last Post: 31st January 2011, 19:15
  2. Replies: 8
    Last Post: 23rd October 2009, 16:33
  3. QTextStream. getting a line?
    By afflictedd2 in forum Qt Programming
    Replies: 1
    Last Post: 8th March 2009, 10:20
  4. Replies: 4
    Last Post: 8th January 2008, 19:41
  5. Adding a line edit in a toolbar
    By borges in forum Qt Tools
    Replies: 1
    Last Post: 16th August 2007, 16:33

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
  •  
Qt is a trademark of The Qt Company.