Home > other >  Qt socket can send pictures and text at the same time
Qt socket can send pictures and text at the same time

Time:09-24

Qt server to send data to the client, I want to send the goods of information, including text and images, the two different data can be sent together, if you can, how the client receive the two different data in slotReadyRead

CodePudding user response:

Can
The client to send, you put the pictures in advance in a function to flow, and then return to QString type, and then send it according to your agreement with the other text line, this is to convert images to flow, and then returns a QString types;
QImage image (fileName);
The QBuffer buffer;
Buffer. The open (QIODevice: : ReadWrite);
Image. The save (& amp; Buffer, "JPG");
QByteArray array;
Array. Append (buffer. The data () toBase64 ());
QString string (array);
QDebug () & lt; return string;
Server receives, in an image when using this function
QString filename="1. JPG";
QString pathname="D:/management_system/item/Server/QRC checkimage/" + filename.
QByteArray array;
Array. Append (string);
QImage image;
Image. LoadFromData (array. FromBase64 (array));
Image. The save (pathname);//to save image to the local
  • Related