my tcpserver 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
}
void UserThread::sendData()
{
qDebug() << "sendData";
#ifdef TEST
qDebug() << "TEST";
QImage image("3.png");
QByteArray ba;
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
}
To copy to clipboard, switch view to plain text mode
client 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
));
}
void MainWindow::readImage(){
qDebug() << socket.bytesAvailable();
QByteArray ba;
ba = socket.readAll();
socket.flush();
qDebug() << ba.size();
QImage image((uchar *)ba.data(),1024,768,QImage::Format_RGB32);
ui->label->setPixmap(QPixmap::fromImage(image));
}
To copy to clipboard, switch view to plain text mode
my picture at attachment
server read the picture sizse is 3145728
but client recevie a wrong size
i used flush
but ...
Bookmarks