[Qt-interest] large xml over the network - problem

franki franki at franki.eu.org
Wed Apr 27 19:43:01 CEST 2011


Wednesday 27 of April 2011 19:10:01 Jeroen De Wachter napisał(a):
> > thanks for reply I'll try quint32 or uint32_t.
> > as to QDataStream I belive I'm using it now, aren't I ?

OK, many thanks, I'll let you know how it works tomorrow.

best regards
Marek

>
> Ah, right... I guess since you had a lenght field, I assumed you were
> manually copying bytes (and I didn't recheck your code for the later
> posts, I must admit)
>
> > QByteArray block;
> > QDataStream out(&block, QIODevice::ReadWrite);
> > out.setVersion(QDataStream::Qt_4_0);
> > out << (quint16)0;
> > out << xml.toString();
> > out.device()->seek(0);
> > out << (quint16)(block.size() - sizeof(quint16));
> > tcpSocket->write(block);
>
> Anyway, you don't need to do any of the length field stuff...
> The QDataStream operators will take care of it.
>
> Try something along the lines of
>
> QByteArray block;
> QDataStream out(&block, QIODevice::ReadWrite);
> out.setVersion(QDataStream::Qt_4_0);
> out << xml.toString();
> tcpSocket->write(block);
>
> you were writing the length twice, anyway... once manually and then
> again because of the QDataStream output operator for QString
> (I should've caught onto this in your original post, really... *sigh* )
>
> The buffering issues I was talking about are also mentioned in the
> documentation, btw:
> http://doc.trolltech.com/4.7/qdatastream.html#QDataStream-2
>
> Oh, and check the return value of that write method, would you? you'll
> want to know if it fails ;-)
>
> Kind regards,
>
> Jeroen





More information about the Qt-interest-old mailing list