[Qt-interest] QTcpSocket Problem
Tang Ke
tangk at lemote.com
Thu Jan 21 03:25:30 CET 2010
On 2010年01月20日 08:18, Dan Mills wrote:
> 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.
>
>
waitForbytesWritten which don't need an event loop, and only write the
data into buffer,but I found that if the io event join the event loop,
sometimes will not work,so I must flush do it youself.
> HTH.
>
> Regards, Dan.
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list