I am not sure why every one has to use QDataStream with QByteArray ??
why???
please have a look the code
writer.write( randomImage() );
stream << (quint32)buffer.data().size();
data.append( buffer.data() );
socket.write( data );
QBuffer buffer;
QImageWriter writer(&buffer, "PNG");
writer.write( randomImage() );
[COLOR="red"]QByteArray data;[/COLOR]
QDataStream stream( &data, QIODevice::WriteOnly );
stream << (quint32)buffer.data().size();
data.append( buffer.data() );
socket.write( data );
To copy to clipboard, switch view to plain text mode
this code is to send a picture.
for same purpose:
writer.write( randomImage() );
stream << (quint32)buffer.data().size();
stream << buffer.data();
QBuffer buffer;
QImageWriter writer(&buffer, "PNG");
writer.write( randomImage() );
QByteArray data;
QDataStream stream(&socket);
stream << (quint32)buffer.data().size();
stream << buffer.data();
To copy to clipboard, switch view to plain text mode
works good as well.
1 i am so confused, what is purpose of having QByteArray in first code???
2 and in second code i don't even need socket.write( ) to send data... why>?
3 in first code, dose "stream << (quint32)buffer.data().size();" means write the size into (QByteArray) data?
Bookmarks