Results 1 to 8 of 8

Thread: Carriage Return in QString

  1. #1
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Carriage Return in QString

    I have a QTextEdit that contains a carriage return.
    I convert to QString :
    Qt Code:
    1. Message = qMessage->toPlainText();
    To copy to clipboard, switch view to plain text mode 
    Then I am unable to remove the carriage return from the QString and replace it with a space character.

    I tried :
    - to split the string with regexp "\r"
    - the stupid
    Qt Code:
    1. for ( int i = 0; i < Message.size(); i++ )
    2. if ( ( Message[i] == QChar(10) ) && ( Message[i+1] == QChar(13) ) ) {
    3. Message[i] = ' ';
    4. Message[i+1] = ' ';
    5. }
    To copy to clipboard, switch view to plain text mode 
    - Message.replace("\r"," ");
    - Message.replace(QRegExp("\r"), " "); even with "0x0D"

    All fails.

    At the end of the modification I copy back my QString to a QTextEdit to display the result and the carriage return is still there. No way to remove it.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Carriage Return in QString

    Try searching for '\n'.

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

    incapacitant (14th May 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Carriage Return in QString

    Of course it works, jacek is not expert but god.

  5. #4
    Join Date
    Jun 2006
    Posts
    8
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Carriage Return in QString

    It may be worth detecting the sequence CR,LF as well.

  6. #5
    Join Date
    Apr 2010
    Posts
    23
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Carriage Return in QString

    Qt Code:
    1. #ifdef linux
    2. QString myNewLine = "\n";
    3. #endif
    4. #ifdef WIN32
    5. QString myNewLine = "\n\r";
    6. #endif
    7. #ifdef __APPLE__
    8. QString myNewLine = "\n";
    9. #endif
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Carriage Return in QString

    Ehm, the thread is 4 (in letters four) years old! But anyway, whats the goal by defining myNewLine? On windows there might be also files which only use new line character. And QTextEdit transforms the different line breakings to "\n", so no need to distinguish.

  8. #7
    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: Carriage Return in QString

    Line 5 has the characters the wrong way around also.

  9. #8

    Default Re: Carriage Return in QString

    Hi Lykurg.

    Is it possible to dispose QtextEdti to do NOT the transormation from \r\n to \n?

Similar Threads

  1. error with QList with a class
    By john_god in forum Newbie
    Replies: 7
    Last Post: 12th January 2009, 21:48
  2. QTableView performances
    By miraks in forum Qt Programming
    Replies: 18
    Last Post: 1st December 2008, 10:25
  3. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 16:26
  4. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  5. Replies: 4
    Last Post: 24th March 2006, 22:50

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.