[Qt-interest] Transferring a QPixmap through QTcpSocket
Joshua W Joseph
joshua at blueprint-group.co.ke
Thu Apr 7 18:41:09 CEST 2011
Thanks alot all of you, especially Thiago,
I finally got it working. The trick was to read the data after the
QTcpSocket connection was closed rather than reading it when
readyRead() was emitted.
Here is my server code:
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_7);
out << ui->lblScreenShot->pixmap()->toImage();
QTcpSocket *client = pixmapServer->nextPendingConnection();
connect (client, SIGNAL(disconnected()), client, SLOT(deleteLater()));
client->write(block);
qDebug() << block.size();
client->disconnectFromHost();
It reads the QPixmap from a label, and here is the client code:
QDataStream in(socket);
in.setVersion(QDataStream::Qt_4_7);
QImage img;
in >> img;
ui->screenshotLabel->setPixmap(QPixmap::fromImage(img));
As you can see, its all so choppy, but at least I can start up from there.
Thanks.
On 4/7/11, Thiago Macieira <thiago at kde.org> wrote:
> On Thursday, 7 de April de 2011 15:54:20 Andre Somers wrote:
>> Op Do, 7 april, 2011 3:28 pm, schreef Thiago Macieira:
>> > Given that the OP was closing the socket just after writing the pixmap
>> > data,
>>
>> > then sending the length in advance is unnecessary. Conclusion:
>> Is it? If you use that, wouldn't you need to check on the receiving end
>> that it was actually the user closing the socket, an not the network
>> connection failing or something like that?
>
> That is correct.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Senior Product Manager - Nokia, Qt Development Frameworks
> PGP/GPG: 0x6EF45358; fingerprint:
> E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
>
More information about the Qt-interest-old
mailing list