[Qt-interest] Transferring a QPixmap through QTcpSocket

Scott Aron Bloom Scott.Bloom at onshorecs.com
Thu Apr 7 14:12:01 CEST 2011


Start off a bit easier...

 

QPixmap is a complex datastructure...

 

Try sending and receiving an integer.. 

Ie

    out << (quint16)0;
    out << 14;
    out << (quint16)(block.size() - sizeof(quint16));
 
and then receive the "14"
 
Once you get that working, it may shed some light on the pixmap
 
Scott

 

From: qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com
[mailto:qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com] On
Behalf Of Joshua W Joseph
Sent: Thursday, April 07, 2011 4:47 AM
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] Transferring a QPixmap through QTcpSocket

 

 

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/78ad459f/attachment.html 


More information about the Qt-interest-old mailing list