if u see the code deeply, then i have closed the file and then for writing the data i was not opening it.
But you said you are getting data in the file, just not the same as you get in the console.
How is it possible you got data in the file if it was closed? (not that I am saying that what you said is not the problem, since obviously you had it corrected, but I still don't understand how this is possible).

is it possible to transfer any kind of binary files like pdf, zip, jpg etc. and recieve it in the same format using the same code listed above? may be the slightest modification i guess would be to use QDataStream rather than QTextStream
Yes, for this you need to use QDataStream if you want to use a tream.
Ah just a second, you are not using QextSerailPort - so you can't use QDataStream.
So you will have to read the input data in binary form and transmit it the same similar to what you have done above.
Nothing speciall actually.