I've tried several approaches. The main problem is retrieving the actual data from the QImage class, and building a new QImage object from that data on the other side.
I tried using QImageWriter to write the image to a file on the hdd, and then using QFile, read the data, and transmit the QByteArray over the socket:
// This code is inside my subclass of QTcpSocket
writer.write(image);
if(write(data))
emit writeln(tr("Write Successful"));
// This code is inside my subclass of QTcpSocket
QImageWriter writer( QString("image.jpg"), "jpg" );
writer.write(image);
QFile imageFile( QString("image.jpg"), this );
QByteArray data = imageFile.readAll();
if(write(data))
emit writeln(tr("Write Successful"));
To copy to clipboard, switch view to plain text mode
Then on the other side I just do this:
QFile out
(tr
("output.jpg"));
out.write(data);
out.close();
QByteArray data = readAll();
QFile out(tr("output.jpg"));
out.open( QIODevice::ReadWrite );
out.write(data);
out.close();
To copy to clipboard, switch view to plain text mode
However, I also tried wrapping the QTcpSocket with QImageWriter, and transmitting that way:
writer.write(image);
QImageWriter writer( this, "jpg" );
writer.write(image);
To copy to clipboard, switch view to plain text mode
Bookmarks