[Qt-interest] QTcpSocket Problem
Dan Mills
dmills at exponent.myzen.co.uk
Wed Jan 20 01:18:04 CET 2010
On Tue, 2010-01-19 at 18:11 -0500, Anthony Gabrielson wrote:
>
> - Server appears to send out the entire file
>
> - Client enters Editor::updateWidget() and successfully enters
> in getFile (work.cpp)
>
> - getFile correctly pulls in the first 35ish kb of data (I
> have verified the files)
>
> - At somepoint, in getFile’s while loop it appears that no
> more bytes are available
>From the QT4 documentation:
"QTcpSocket works asynchronously and emits signals to report status
changes and errors, just like QHttp and QFtp. It relies on the event
loop to detect incoming data and to automatically flush outgoing data.
You can write data to the socket using QTcpSocket::write(), and read
data using QTcpSocket::read(). QTcpSocket represents two independent
streams of data: one for reading and one for writing."
The key thing is that the event loop is not being run while you sit and
spin in the while loop.
Try either using the waitFor... methods in QTcpSocket (which don't need
an event loop) which will work but will freeze the GUI until the
download completes, or rewrite using a slot to handle the data when it
becomes available.
HTH.
Regards, Dan.
More information about the Qt-interest-old
mailing list