简体   繁体   English

在 Qt 中处理大量数据

[英]Handle huge amount of data in Qt

I need to read some text files that contain a huge amount of data, say 4 files each of about 500MB.我需要阅读一些包含大量数据的文本文件,比如 4 个文件,每个文件大约 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.到目前为止,我的策略是解析每个文件并为每一行创建一个 QTreeWidgetItem ,其中包含合适数量的字段来存储该行(这是因为在程序期间我想在 QTreeWidget 中显示其中一些数据)并将所有这些项目附加到一个 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.这个 QList 是为程序的所有执行而存储的,这样数据总是可用的,我不再需要解析文件了。

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.然而,这种策略在资源方面似乎过于庞大,因为我看到该程序消耗了几 GB 的内存并最终崩溃。

How can I approach in a better way the handling of such data?如何以更好的方式处理此类数据?

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() . Qt 文档中有一个示例,它向您展示了如何使用QAbstractItemModelcanFetchMore()fetchMore()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM