[Qt-interest] Send a pdf thru QTcpSocket. Encoding problem?

Josinei Silva josinei_listas at yahoo.com.br
Wed Feb 4 13:28:37 CET 2009


Thiago,

Em Wednesday 04 February 2009 06:20:58 Thiago Macieira escreveu:
> Josinei Silva wrote:
> >I'm trying to send a pdf created by my own Qt application printing to a
> > file thru a QTcpSocket ( It's working with threads now. Thanks Thiago
> > ). But the pdf that i received is not the same i sent.
>
> Why are you using base 64 and QDataStream?

First, i tried without base 64 but it didn't work. the file i received was 
missing the end.

> Why not just send the byte
> array size and the byte array itself?

I 'm doing the way i saw at documentation samples. It's working fine when data 
sent is text only. I'll try to do it without QDataStream.

> The base64 encoding is completely
> unnecessary, since your channel is 8-bit clean.

Ok, it's my first time with tcp socket and i not sure about encoding and tcp 
connections. So, when the first try failed, i thought it was because encoding 
due warnings i saw in documentation.

> Just be careful with endianness when sending the size.

You mean to make sure thtat byte array size have the same length when i send 
and when i receive?

> Also note the following potential errors:
>  - waitForBytesWritten waits for any bytes written, not ALL bytes written
>  - there's no code in the receiving side to wait for all necessary bytes
> 	to arrive
>  - you write a QByteArray into the QDataStream, but you read a QString

Thanks for these tips, I'll think about it.

Thnks

Josinei



More information about the Qt-interest-old mailing list