PDA

View Full Version : How can we handle large files in qt?



aurora
13th February 2012, 11:04
Is there any good way for handling text files of hundred of bytes?
If there any such please tell me...

I my GUI program, i need to read very large files (around 200MB..!!!) and need to perform search operation on that...
I am reading line by line and displaying them in QTableWidget but as the file size increases, program crashes or hangs....what should i do, in this case?
How can i load such big files in QTableWidget?
How can i perform searching efficiently on them?
Does Qt provides any good mechanism for these kind of problems?

marcvanriet
13th February 2012, 11:51
A 200 MB text file will contain about two million text lines. There is no point in creating a table with two million rows, no-one will ever scroll through all of them.

You can read the file, and then display only the first e.g. 1000 lines that match your search criterium.

Or you could write a datamodel class for your text file, and then use a QTableView widget, and the view will request only the data for the rows that need to be displayed. But I don't know how much about this, so I don't know if it is easy to do.

Best regards,
Marc

MarekR22
13th February 2012, 13:15
Most probably you have used QStandardItemModel, which is good only for small amount of data.
Most probably you should store your data in more compact way (some structure and QVector) and expose it to QTableView by properly subclassing QAbstractTableModel. Then handling data from text file size 500MB shouldn't be a problem.

In some spatial cases when you have relay big set of data you can use: QCache or QContiguousCache.