[Qt-interest] Send a pdf thru QTcpSocket. Encoding problem?
Josinei Silva
josinei_listas at yahoo.com.br
Wed Feb 4 02:57:04 CET 2009
Hi,
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.
This is the code used to send the file:
QFile ReportFile( FileName );
ReportFile.open( QIODevice::ReadOnly | QIODevice::Text );
QString OutPut;
QByteArray ReportArray = ReportFile.readAll();
OutPut = ReportArray.toBase64();
QByteArray Block;
QDataStream Out( &Block, QIODevice::WriteOnly );
Out.setVersion( QDataStream::Qt_4_0 );
Out << (quint16)0;
Out << OutPut;
Out.device()->seek( 0 );
Out << (quint16)( Block.size() - sizeof(quint16) );
tcpSocket.write( Block );
tcpSocket.waitForBytesWritten( TimeOut );
This is the code used to receive the file:
QDataStream In( tcpSocket );
In.setVersion( QDataStream::Qt_4_0 );
quint16 BlockSize = 0;
if ( tcpSocket->bytesAvailable() >= (int)sizeof(quint16) )
{
In >> BlockSize;
if ( tcpSocket->bytesAvailable() >= BlockSize )
{
QString Report;
In >> Report;
QFile *File = FileOpen( FileName );
QByteArray ReportArray = QByteArray::fromBase64( Report.toAscii()
);
File->write( ReportArray );
File->close();
}
}
I saved the contens of "OutPut" and "Report" and they are the same. I think
thar sending the encoded string it is not a problem. But i must be doing
something wrong when encoding and decoding the pdf. I tried to send without
encode but it doesn't look to work.
How can i encode and decode this file to send thru the QTcpSocket?
Thanks
Josinei
More information about the Qt-interest-old
mailing list