Textarea 记录速度慢 [英] Textarea slow for logging

查看:65
本文介绍了Textarea 记录速度慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Qt 应用程序,我想显示一些日志.我使用 TextArea.但是,如果日志很大或事件发生得太快,GUI 无法足够快地绘制 Textarea.

I have a Qt application and I'd like to show some log. I use a TextArea. However, if the log is large or the events come too fast the GUI can't draw Textarea fast enough.

我已经用 Qt Creator (QML Profiler) 分析过这个问题,如果日志很大,绘制 GUI 需要 300 毫秒.我在 Raspberry Pi2 上使用此软件.

I have analyzed this problem with Qt Creator (QML Profiler) and if the log is large it takes 300 ms to draw the GUI. I use this software on a Raspberry Pi2.

任何想法如何解决这个问题?我应该使用其他 QML 控件吗?谢谢.

Any ideas how to solve this? Should I use other QML controls? Thanks.

QML 代码:

TextArea {
    text: appHandler.rawCommunication
    readOnly: true        
}

C++ 代码:

Q_PROPERTY(QString rawCommunication READ rawCommunication WRITE setrawCommunication NOTIFY rawCommunicationChanged)

void setrawCommunication(QString val)
{
    val.append("\n");
    val.append(m_rawCommunication);
    m_rawCommunication = val;
    emit rawCommunicationChanged(m_rawCommunication);
}

推荐答案

使用 视图,例如 ListView.他们根据需要实例化他们的委托,基于视图需要显示哪些数据取决于用户在列表中的位置.这意味着与 TextArea 之类的项目相比,它们在可视化大量数据方面的表现要好得多,在您的情况下,它们将在内存中保留大量、不断增长的字符串.

Use a view, like ListView. They instantiate their delegates as needed, based on which data the view says it needs to show depending on the position the user is at in the list. This means that they perform much better for visualising large amounts of data than items like TextArea, which in your case is going to keep a massive, ever-growing string in memory.

您的代表可以是TextArea,因此每个日志行都有一个可编辑的文本块.但是,如果您不需要样式,我建议您使用更轻松的东西,例如 TextEdit.更进一步:如果您不需要可编辑的文本,请使用普通的旧 Text.切换到这些可能没有太大区别,但如果您仍然看到速度缓慢(并且一次有很多代表可见),那么值得一试.

Your delegate could then be a TextArea, so you'd have one editable block of text per log line. However, if you don't need styling, I'd recommend going with something a bit lighter, like TextEdit. Taking it one step further: if you don't need editable text, use plain old Text. Switching to these might not make much of a difference, but if you're still seeing slowness (and have lots of delegates visible at a time), it's worth a try.

这篇关于Textarea 记录速度慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆