[Qt-interest] Transferring a QPixmap through QTcpSocket
Joshua W Joseph
joshua at blueprint-group.co.ke
Thu Apr 7 14:06:47 CEST 2011
On Thu, Apr 7, 2011 at 2:47 PM, Andre Somers <andre at familiesomers.nl> wrote:
> Op Do, 7 april, 2011 1:34 pm, schreef sarvesh saran:
> > On Thu, Apr 7, 2011 at 4:30 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.
> >>
> >>
> >>
> >> The client receives some data, but how to I:
> >> 1. Ensure that all of the sent data is received, and
> >>
> >
> > your code is ensuring this already.
> >
> >
> >
> >> 2. Convert the received data into a QPixmap so that it can be
> >> displayed.
> >>
> >
> > the operator>> takes care of that (
> > http://doc.qt.nokia.com/latest/qpixmap.html#operator-lt-lt-101).....its
> > all
> > there in your code!
>
> Sorry, but that is wrong. It might very well be that you get the signal
> that you have data to read, but not all data is available yet and trying
> to use the >> operator on QDataStream to read the image will result in a
> crash.
>
> However, it seems that you are already waiting to see if you have received
> all the data. What I would do, is stream first stream out the QPixmap to a
> buffer. Then, see how big that buffer is, stream that out as a quint64,
> and then stream out the raw data from the buffer to the network. This way,
> you can first read the size of the image to expect, and then only if you
> have received the complete data, read out the actual QPixmap. Note that
> you also might store the image data in a buffer on the receiving end
> untill the size of that buffer matches the size you received as the image
> size.
>
> André
>
> Thank you Andre, let me see what I will get from your procedure
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110407/cd0fb95d/attachment.html
More information about the Qt-interest-old
mailing list