我正在创建一个应用程序,我需要通过 tcp 发送一些图像。
发送部分是
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 通信正常,因为仅包含文本的其他消息通过正常...
有任何想法吗?
提前致谢!