1 Attachment(s)
how to use qtcpsocket send qimage data
my tcpserver code
Code:
void UserThread::sendData()
{
qDebug() << "sendData";
#ifdef TEST
qDebug() << "TEST";
qDebug() << image.byteCount() <<image.size();
ba.append((char *)image.bits(),image.byteCount());
qDebug() <<ba.size();
this->m_tcpSocket->write(ba);
if(!this->m_tcpSocket->waitForBytesWritten(-1))
{
qDebug() << "writen Bytes error " << this->m_tcpSocket->errorString();
}
this->m_tcpSocket->flush();
#endif
}
client code
Code:
void MainWindow::readImage(){
qDebug() << socket.bytesAvailable();
ba = socket.readAll();
socket.flush();
qDebug() << ba.size();
QImage image
((uchar
*)ba.
data(),
1024,
768,
QImage::Format_RGB32);
ui
->label
->setPixmap
(QPixmap::fromImage(image
));
}
my picture at attachment
server read the picture sizse is 3145728
but client recevie a wrong size
i used flush
but ...
Re: how to use qtcpsocket send qimage data
Quote:
server read the picture sizse is 3145728
but client recevie a wrong size
Try looping on the clinet side until your buffer gets filled with the correct size.
Code:
//This is pseudo code
while((size < imageSize) && !bTimeout)
{
ba.append(socket.readAll());
}
you don't need to call flush() on the client side.
Re: how to use qtcpsocket send qimage data
server read the picture sizse is 3145728
but client recevie a wrong size
TCP will break up your bytearray into lots of different packets which you must append to the socket bytearray... you need them all for the complete image. (readAll() only reads all of the first packet).