Results 1 to 7 of 7

Thread: QTextEdit Help pls

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    10
    Thanked 80 Times in 74 Posts

    Default QTextEdit Help pls

    Hi,

    I am accepting a multi line text from user in a QTextEdit. I first store it in a string using toPlainText and then store it in a database. But when I retrieve the data from the database my text comes in single line. All the new line characters are lost. Can someone please help ?

    Thanks a lot

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

    Default Re: QTextEdit Help pls

    Are you sure that after toPlainText() your text is still multilined? Try to write it to the console using qWarning().

  3. #3
    Join Date
    Jan 2006
    Posts
    667
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    10
    Thanked 80 Times in 74 Posts

    Default Re: QTextEdit Help pls

    When I debug I see that whereever '\n' has to come a box like character comes.

    Please Help

    Thanks a lot.

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

    Default Re: QTextEdit Help pls

    Check its ascii number.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QTextEdit Help pls

    Even because this works fine with a multiline text;
    Qt Code:
    1. textEdit->setPlainText(textEdit->toPlainText());
    To copy to clipboard, switch view to plain text mode 
    one could come to a conclusion that the problem is on the db side.
    So how does it look if you write the text fetched from the db to the console?
    J-P Nurmi

  6. #6
    Join Date
    Jan 2006
    Posts
    667
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    10
    Thanked 80 Times in 74 Posts

    Default Re: QTextEdit Help pls

    Hi,

    I am using SQLite and I have a sqlite brower which shows the data correctly.

    The problem is when I convert from QVariant to QString the new line character is lost.

    Plese Help
    Thanks a lot.

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QTextEdit Help pls

    Quote Originally Posted by munna
    I am using SQLite and I have a sqlite brower which shows the data correctly.
    So did you try to output the string after fetching it from the database? And even analyze it more deeply, for example output all of it's chars to see if there are line break characters at all, and if there is, what characters are they, NL/CR/?
    Qt Code:
    1. QChar* data = str.data();
    2. while (!data->isNull()) {
    3. qDebug() << data->unicode();
    4. ++data;
    5. }
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by munna
    The problem is when I convert from QVariant to QString the new line character is lost.
    I don't think that the problem lies in QVariant at all. I highly doubt that QVariant touches the string in any way.
    At least this works fine and outputs line breaks correctly:
    Qt Code:
    1. void testSlot() {
    2. QVariant v = toPlainText();
    3. qDebug() << v;
    4. setPlainText(v.toString());
    5. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. QTextEdit Performance handling large paragraphs
    By netuno in forum Qt Programming
    Replies: 14
    Last Post: 1st September 2010, 23:58
  2. Drawing on QTextEdit
    By jgrauman in forum Qt Programming
    Replies: 3
    Last Post: 7th February 2009, 10:40
  3. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 13:05
  4. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 07:03
  5. Obtaining clean (x)html from QTextEdit
    By ccf_h in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2006, 15:47

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.