I want to know what is the optimal bufferSize in the above code so that we do not get any runtime issue .

Generally bigger buffers tend to perform faster, but there's saturation to that effect. It depends on the application itself, the OS, the drivers and ultimately the hardware, so there's no "correct" size. For files of the size up to 1-2 GB I'd think 1MB is reasonable, for larger files I'd consider making the buffer larger as well.

Kind regards.

Even if we accept, as the basic tenet of true democracy, that one moron is equal to one genius, is it necessary to go a further step and hold that two morons are better than one genius?

There's no such thing. There's an internal buffer in QTextStream but it bears no consequence here. It'll be flushed on device close or on QTextStream::endl/QTextStream::flush. So the stream has no notion of size, it's a stream.

Kind regards.

Even if we accept, as the basic tenet of true democracy, that one moron is equal to one genius, is it necessary to go a further step and hold that two morons are better than one genius?

@Qt-Enthusiast
Sorry for the late reply, I somehow missed the notification.

Because in our case File sizes can go to 2 -3 GBS

The problem is not with the QTextStream in this case. It's with how much of the file you want to read. On a 32 bit OS this is close to impossible, because you'd be pushing the memory limit reading a file that big in one go. An alternative to reading the whole file is to process it in parts instead. Perhaps the QFile's memory mapping API might be of use in your case.

I want to know that the tool does not crash even for the following line

QTextStream ts(fp, QIODevice::ReadOnly);

This does next to nothing. It will create an object that wraps around the QIODevice/FILE * and will have an empty buffer. As I said it's a stream, it doesn't read anything by itself, and it has no notion of size. Anything you read from the file will be returned, anything you write to the stream will be buffered and actually written when the stream is flushed. That's all. There's no big secret with the buffer or its size. It's just put there for a minor optimization (and has no bearing on your problem here, as I stated before).

Kind regards.

Even if we accept, as the basic tenet of true democracy, that one moron is equal to one genius, is it necessary to go a further step and hold that two morons are better than one genius?