Skip to content Skip to sidebar Skip to footer

Receiving Data With Spaces, Thru Sockets

I'm using C++ with QT4 for this. And when I try to send large html files(in this case, 8kb), the process of sending and receiving work well. But the file received come with spaces

Solution 1:

The stuff you are getting back in the file is not your original text, but QString serialization form, which is unsuprisingly UTF-16. If you want your text back, read the input QDataStream back to QString and save that into file.

While prefixing your data with a length is generally a good idea, it is absolutely redundant with QString >> QDataStream. Read up something here or here. Moreover you have developed a mind boggingly obfuscated way which i suspect is doing nothing. QByteArray is not implementing QIODevice (indeed, why it should) so your out.device()->seek() is a base virtual implementation, empty and just returning true. I won't be surprised if your length "header" is found at the end of your serialization dump file.

Edit: i think that your html transport might start working correctly only by leaving out the confused quint operation completely and use out QTextStream instead of QByteStream.

Solution 2:

I posted the solution for my case in the other post.

Thanks you all for the attention

Post a Comment for "Receiving Data With Spaces, Thru Sockets"