PDA

View Full Version : Using QTcpSocket



mraittin
2nd September 2007, 09:18
How can I send image from server to client using QTcpSocket?
......

connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendImage()));
......
void Server::sendImage()
{
QTcpSocket* socket = static_cast<QTcpSocket*>(sender());
socket = tcpServer->nextPendingConnection();
QImage image("image.jpeg");

QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "jpeg");

socket->write(ba);
}



I'am quite newbie with QT and QTcpSocket.
Thank advance.

marcel
2nd September 2007, 09:54
See the attachments in this thread(post #19): http://www.qtcentre.org/forum/f-qt-programming-2/t-tcpsocketserver-8502.html.

It is exactly the same problem. The file is sent in buffers, but you can modify how that is done.

Regards