找回密码
 立即注册
收起左侧

串口通讯中使用QPlainTextEdit 大量显示后阻塞的问题

2
回复
10545
查看
[复制链接]
累计签到:2 天
连续签到:1 天
来源: 2014-2-19 13:56:40 显示全部楼层 |阅读模式
1Qter豆
问题如题:
ui->plainTextEdit->insertPlainText(hex);
现在的串口调试助手的程序大多使用Qt提供的QPlainTextEdit类来实现文本的显示,经过反复的试验,当此对象中缓冲了大量的字节时就会出现卡顿的情况。现在提出一些猜测和解决方法,还望高人指点。
1.卡顿的原因在于大量字节的显示需要在QFrame重绘,显示的文本越大工作量也越大。
2.参考一些其他的类似工具例如windows自带的超级终端,或者是一些用VB写的小工具,都会限制显示文本的数量,或者是限制显示的区块,这项功能如何操作。
3.想让plainTextEdit->insertPlainText(hex);达到超大文本记录的功能,同时GUI又不出现卡顿,使用区块显示+其余存入文件不知可否?怎么实现


最佳答案

查看完整内容

下面是QT帮助文档是的一篇文档,没有深入研究,贴出来大家看一下: Handling Large Files Qt does not limit the size of files that are used for text processing. In most cases, this will not present a problem. For especially large files, however, you might experience that your application will become unresponsive or that you will run out of memory. The size of the files you can load depends on your ha ...
回复

使用道具 举报

累计签到:1570 天
连续签到:1 天
2014-2-19 13:56:41 显示全部楼层
下面是QT帮助文档是的一篇文档,没有深入研究,贴出来大家看一下:


Handling Large Files

Qt does not limit the size of files that are used for text processing. In most cases, this will not present a problem. For especially large files, however, you might experience that your application will become unresponsive or that you will run out of memory. The size of the files you can load depends on your hardware and on Qt's and your own application's implementation.

If you are faced with this problem, we recommend that you address the following issues:

You should consider breaking up large paragraphs into smaller ones as Qt handles small paragraphs better. You could also insert line breaks at regular intervals, which will look the same as one large paragraph in a QTextEdit.
You can reduce the amount of blocks in a QTextDocument with maximumBlockCount(). The document is only as large as the number of blocks as far as QTextEdit is concerned.
When adding text to a text edit, it is an advantage to add it in an edit block (see example below). The result is that the text edit does not need to build the entire document structure at once.
We give an example of the latter technique from the list. We assume that the text edit is visible.

textEdit.show();

textCursor.beginEditBlock();

for (int i = 0; i < 1000; ++i) {
     textCursor.insertBlock();
     textCursor.insertText(paragraphText.at(i));
}

textCursor.endEditBlock();
回复

使用道具 举报

尚未签到

2014-9-1 21:25:29 显示全部楼层
坛主,研究一下吧,我也遇到这个问题,上面的代码好像会自动换行。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了