[Qt-interest] Transferring a QPixmap through QTcpSocket
Joshua W Joseph
joshua at blueprint-group.co.ke
Thu Apr 7 13:47:27 CEST 2011
On Thu, Apr 7, 2011 at 2:42 PM, Joshua W Joseph <
joshua at blueprint-group.co.ke> wrote:
> Thank you all.
> Its really unnerving me, because I have the process well mapped but I am
> really unable to implement the idea. The resulting QPixmap is invalid, and
> when loaded onto a QLabel nothing is displayed.
>
> Thank you all for your responses.
>
>
> On Thu, Apr 7, 2011 at 2:00 PM, Joshua W Joseph <
> joshua at blueprint-group.co.ke> wrote:
>
>> Hi All,
>>
>> I have two simple applications which are network based. The 'server' takes
>> a screenshot of its computer. When a 'client' connects, it will receive the
>> captured image. These are basically the fortune server/client examples
>> modified to transmit images instead of text.
>>
>> Here is my code for sending the image:
>>
>> QByteArray block;
>>
>> QDataStream out(&block, QIODevice::WriteOnly);
>>
>> out.setVersion(QDataStream::Qt_4_0);
>>
>> out << (quint16)0;
>>
>> out << originalPixmap;
>>
>> qDebug() << "Pixmap Sent";
>>
>> out.device()->seek(0);
>>
>> out << (quint16)(block.size() - sizeof(quint16));
>>
>> QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
>>
>> connect(clientConnection, SIGNAL(disconnected()),
>>
>> clientConnection, SLOT(deleteLater()));
>>
>> clientConnection->write(block);
>>
>> clientConnection->disconnectFromHost();
>>
>>
>> And here is my code for reading it
>>
>> QDataStream in(tcpSocket);
>>
>> in.setVersion(QDataStream::Qt_4_0);
>>
>> if (blockSize == 0) {
>>
>> if (tcpSocket->bytesAvailable() < (int)sizeof(quint64))
>>
>> return;
>>
>> in >> blockSize;
>>
>> }
>>
>> if (tcpSocket->bytesAvailable() < blockSize)
>>
>> return;
>>
>> QPixmap nextPixmap;
>>
>> in >> nextPixmap;
>>
>> originalPixmap = currentPixmap;
>>
>> updateScreenshotLabel();
>>
>> getFortuneButton->setEnabled(true);
>>
>> received = false;
>>
>>
>>
>> The client receives some data, but how to I:
>> 1. Ensure that all of the sent data is received, and
>> 2. Convert the received data into a QPixmap so that it can be
>> displayed.
>>
>> I know it sounds simple but i have racked my brains for several days now
>> and I just cant seem to get it. Please assist.
>>
>> Thank you in advance,
>>
>> Joshua W.
>>
>
> I am getting these errors:
QPixmap::scaled: Pixmap is a null pixmap
QSize(-1, -1)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110407/664c86c1/attachment.html
More information about the Qt-interest-old
mailing list