Search code examples
qtqt4qtcpsocketqtcpserver

Strange characters when transferring file with QTcpSocket


I'm trying to transfer a file using a QTcpSocket. The connection runs fine, but my problem is when I try to record the received bytes on a file. When I open the file there are some strange characters at the beginning of the file. What are these characters?


Solution

  • My problem was that I was saving the whole object in my file. When we use the operator >> in a stream, the Qt serializes the whole object and sends it. If you want write only the bytes of your file, or whatever you want, you need to use writeRawData or the write methods passing the char * for the bytes.

    :)