0
我正在创建一个应用程序,我需要通过tcp发送一些图像。通过qtcpsocket发送qimage:只接收部分数据
发送部分是
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();
和客户端:
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.");
}
的问题是,当服务器似乎被发送的所有数据, 客户端接收仅将报头..
(当然程序崩溃在线
image.loadFromData(buffer.data());
的TCP通信工程确定,因为只包含文字经过确定的其他消息...
任何想法?
在此先感谢!