Transferring images over qudpsocket in qt
I am trying to send an image file over qudpsocket.The code I used to send a cpp file is given below.8388 is the size of the file.
@ QFile file1("/home/test.cpp");
bytes = in.read(8838).toLatin1();
and I received the file using the code give below.
@QFile file("received.txt"); file.resize(0); file.open(QIODevice::Append); QTextStream out(&file); QByteArray data; data.resize(socket->pendingDatagramSize()); socket->readDatagram(data.data(),data.size()); QString str=data.data(); out << data;@
How ever when I transmit an jpeg file like this.How to get the image file to Qdatastream and send like this easily and receive at the client end..Pleas help
It all about serializing your binary file in to byte-array and passing it.
QImageWriter writer(&buffer, "JPQ");
data.append( buffer.data() );
At service side also use the QDataStream to reach appropriately. I have not tried.
thanks a lot.That was what I am searching for.