处理QT中的大量数据

发布于 2025-02-05 01:09:19 字数 424 浏览 5 评论 0原文

我需要阅读一些包含大量数据的文本文件,例如约500MB中的4个文件。

每个文件都包含几行,每行都具有这种格式:

id timestamp field1 field2 field3 field4

到目前为止,我的策略是解析每个文件,并且对于每行创建一个QTREEWIDGETITEM,并具有适当数量的字段来存储该行(这是因为在程序中,我想显示一些在qtreewidget中的这些数据中),并将所有这些项目附加到Qlist中。

此QLIST存储用于程序的所有执行,以这种方式,数据始终可用,我不再需要解析文件。

我需要所有可用的数据,因为在每一刻,我需要相对于特定时间戳间隔访问数据。

但是,这种策略在资源方面似乎太广泛了,因为我看到该程序消耗了几个GB的内存,并且最终会崩溃。

如何更好地处理此类数据?

I need to read some text files that contain a huge amount of data, say 4 files each of about 500MB.

Each file contains several lines and each line has about this format:

id timestamp field1 field2 field3 field4

My strategy so far was to parse each file and for every line creating a QTreeWidgetItem with a suitable number of fields to store that line (this because during the program I want to show some of these data in a QTreeWidget) and appending all these items to a QList.

This QList is stored for all the execution of the program, in this way data are always available and I don't need to parse the files anymore.

I need all the data available because at each moment I need to access to data relative to a particular timestamp interval.

However this strategy seems too expansive in terms of resources, because I saw that the program consumes several GBs of memory and it eventually crashes.

How can I approach in a better way the handling of such data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不即不离 2025-02-12 01:09:19

What you want is called 'lazy loading'.
There is an Example in the Qt documentation which shows you, how to use QAbstractItemModel, canFetchMore() and fetchMore().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文