C++ 如何在 QT 的 QTextBrowser 中附加文本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8846691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 19:13:20  来源:igfitidea点击:

How to append text in a QTextBrowser in QT?

c++qtfilestreamqtextbrowser

提问by iloahz

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

我创建了一个QTextBrowser用于显示大量数据(实际上是显示运行时日志),它是在另一个进程中动态生成的。

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.

我发现我可以fopen("log.html","a")用来将数据附加到实际的日志文件中,并且reload()每次更新时都可以使用它,但我认为这效率不高,甚至可能是不明智的。

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

我想知道是否有一种巧妙的方法来实现这一点。

回答by TonyK

QTextBrowserinherits QTextEdit, so you can use QTextEdit::append:

QTextBrowser继承QTextEdit,所以你可以使用QTextEdit::append

void QTextEdit::append ( const QString & text )

回答by Liam M

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

写到一半,补充 TonyK 的回答:

Perhaps the appendMethod is what you're looking for?

也许append方法就是你要找的?

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().

在文本编辑的末尾附加一个带有文本的新段落。附加的新段落将具有与当前段落相同的字符格式和块格式,由光标的位置决定。另见 currentCharFormat() 和 QTextCursor::blockFormat()。