tsuibin
7th November 2010, 04:36
my tcpserver code
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
}
client code
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));
}
my picture at attachment
server read the picture sizse is 3145728
but client recevie a wrong size
i used flush
but ...
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
}
client code
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));
}
my picture at attachment
server read the picture sizse is 3145728
but client recevie a wrong size
i used flush
but ...