[Qt-interest] large xml over the network - problem
franki
franki at franki.eu.org
Thu Apr 28 12:22:48 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 ?
Hello,
It work's fine with quint32 instead of quint16,
it would probably have worked without my length value at the beginning as
QDataStream also uses 32 bit integer to write length of the string, but then,
when reading I would have to do:
in >> text;
without checking how many data there is in fact in buffer, and with slow
connection and lots of data I could freeze app for a moment, so just to be on
a safe side I'll leave it as it is.
many thanks
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