PDA

View Full Version : Send a Image throw a QDataStream



gt.beta2
16th March 2009, 18:43
Hi!

About this code:

QByteArray datagram;
QDataStream out(&datagram, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_1);
out << x << y << z;
udpSocket->writeDatagram(datagram, QHostAddress::Broadcast, 45454);

I tried this with int, float, ... and it works.
Can i load an image from the images resource into x and the send it? If so what object should i use? QImage?

The final idea is to load the image into an object (label) in the receiver GUI.

Thanks

wysota
16th March 2009, 23:46
You can send it directly as QImage. Look that it has redirect operators to/from QDataStream.

gt.beta2
17th March 2009, 16:36
Thanks for the tip.
You leaded me here where i found the list of suported objects: Format of the QDataStream Operators (http://doc.trolltech.com/4.5/datastreamformat.html)

gt.beta2
18th March 2009, 23:23
If i use QDataStream::Qt_4_0 data serialization format to write data to the stream, do i have to use the same format when reading it?
Is the some sort of compatibility?
Thanks

wysota
18th March 2009, 23:31
The docs are very clear about this, so it's best if you take a look at them. See QDataStream::setVersion().

gt.beta2
20th March 2009, 23:07
I can only say :o