Reading the file content
-
Hi All
I have a file of size 1GB,I was reading this file using below code
QString data = file.readAll();
But the above code is not working properly.
Can any one tell me which is the best way to read the contents of big file but i want data to be in QString[i.e full file content]
-
Do you really, really want to read a 1GB file in one go, and put it all in a QString? Note that QString internally uses UTF-16 as the storage format; that means at least two bytes per character. Depending on the encoding of the file you are trying to read, that might result in a 2 GB block of memory needed for your QString alone.
Think if you can read and process the file in pieces instead.
-
Oh, and you're probably doubling the memory consumption, as readAll() returns a QByteArray, that is fed to the QString constructor, which most probably will copy the data. So you will have 1GB in the QByteArray and roughly 2GB in the QString. In total you need 3GB - at least until the QString constructor is done.