i am creating an application where i need to send some images over tcp.
the sending part is
QImage image;
image.load("image.png", "PNG");
image.setText("name", "color");
QByteArray ba;
QBuffer buffer(&ba);
image.save(&buffer, "PNG");
int bsize = ba.size();
sendData(MESSAGE_BACKGROUND_COLOR, QString::number(ba.size()).toStdString());
int bsent = m_tcpSocket->write(ba, ba.size());
if(!m_tcpSocket->waitForBytesWritten(-1))
{
qDebug() << "written Bytes error " << m_tcpSocket->errorString();
}
m_tcpSocket->flush();
and the client:
QByteArray buffer;
buffer = m_ConnectedClients[i]->read(messageSize);
int bytesS = buffer.size();
QImage image;
image.loadFromData(buffer.data());
if (image.isNull())
{
qDebug("The image is null. Something failed.");
}
The problem is that where the server seems to be sending all the data,
the client receives only the header...
(and of-course the program crashes in line
image.loadFromData(buffer.data());
The tcp communication works ok, since other messages containing only text go through ok...
Any ideas?
Thanks in advance!