How to append text in a QTextBrowser in QT?
Asked Answered
C

2

6

I have created a QTextBrowser to display a large amount of data (actually displaying the run time log), which is dynamically generated in another processes.

I have found out that I can use fopen("log.html","a") to append data to an actually log file, and reload() it every time it's updated, but I think that's not efficient, or even possibly unwise.

I wonder if there's a neat way to implement this.

Cherisecherish answered 13/1, 2012 at 6:17 Comment(1)
If you need a more performant version of append, you need to access the internal QTextDocument.Precipitate
B
10

Got half way through writing this, supplemental to TonyK's answer:

Perhaps the append Method is what you're looking for?

Appends a new paragraph with text to the end of the text edit. The new paragraph appended will have the same character format and block format as the current paragraph, determined by the position of the cursor. See also currentCharFormat() and QTextCursor::blockFormat().

Bach answered 13/1, 2012 at 6:36 Comment(0)
C
26

QTextBrowser inherits QTextEdit, so you can use QTextEdit::append:

void QTextEdit::append ( const QString & text )
Cide answered 13/1, 2012 at 6:33 Comment(2)
Thank you all the same! however i don't know how to choose multiple answersCherisecherish
@Topro: There can be only one accepted answer (with the green tick), but you can upvote as many answers as you like. To do so, you must click the little triangle pointing upward on the left of the answer. Similarly, if you think an answer is wrong or does not provide any useful information, you can downvote it with the triangle pointing downward.Nagano
B
10

Got half way through writing this, supplemental to TonyK's answer:

Perhaps the append Method is what you're looking for?

Appends a new paragraph with text to the end of the text edit. The new paragraph appended will have the same character format and block format as the current paragraph, determined by the position of the cursor. See also currentCharFormat() and QTextCursor::blockFormat().

Bach answered 13/1, 2012 at 6:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.