Results 1 to 5 of 5

Thread: QTextBrowser Grab Last Line Of Output

  1. #1
    Join Date
    Oct 2008
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTextBrowser Grab Last Line Of Output

    First of all, I'm new to these forums so hi to all.

    I need to know what options are available to me if I want to grab the last line of input from a QTextBrowser object, so I can do whatever processing I need to do with it.

    If you need any more information then please let me know.

    Many Thanks.

  2. #2
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextBrowser Grab Last Line Of Output

    Do you mean
    1. the very last line of the whole document in the QTextBrowser (the bottom line), or
    2. the last line chronological seen?

    1. You can move the cursor to the end of document: From there you can select the text until the line start. After that you ask the cursor to return the selected text.
    Qt Code:
    1. ui.textEdit->moveCursor( QTextCursor::End );
    2. ui.textEdit->moveCursor( QTextCursor::StartOfLine, QTextCursor::KeepAnchor );
    3. QString text = ui.textEdit->cursor().selectedText();
    To copy to clipboard, switch view to plain text mode 
    Code is untested, but it should lead the way.

    2. Place the cursor to the end of the line you just edited and do the same as above .

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

    crisp (11th October 2008)

  4. #3
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextBrowser Grab Last Line Of Output

    depending on how your text browser is filled, you could use:

    string = textBrowser->toHtml(); or
    string = textBrowser->toPlainText ();

    and then use QString::lastIndexOf() to find where the return character that separates the last line from the one before it, then use that index in:
    QString::mid ( int position) so that it takes everything from that return character to the end.

  5. #4
    Join Date
    Oct 2008
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextBrowser Grab Last Line Of Output

    Apologies for the ambiguity there, and many thanks to both of you, that helped a lot.

  6. #5
    Join Date
    Jan 2006
    Posts
    369
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextBrowser Grab Last Line Of Output

    Quote Originally Posted by tpf80 View Post
    depending on how your text browser is filled, you could use:

    string = textBrowser->toHtml(); or
    string = textBrowser->toPlainText ();

    and then use QString::lastIndexOf() to find where the return character that separates the last line from the one before it, then use that index in:
    QString::mid ( int position) so that it takes everything from that return character to the end.
    huge performance pennalty! bad! bad! and if the text editor has richtext, the last line... is it? <br>? or </p>? or </div>?

    the QTextCursor is the way to go IMHO.

  7. The following user says thank you to elcuco for this useful post:

    crisp (11th October 2008)

Similar Threads

  1. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 05:34
  2. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  3. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

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.