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

Jeroen De Wachter jeroen.dewachter at elis.ugent.be
Wed Apr 27 19:10:01 CEST 2011


> thanks for reply I'll try quint32 or uint32_t.
> as to QDataStream I belive I'm using it now, aren't I ?

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