[Qt-interest] QTcpSocket::connectToHost() is blocking the GUI!
Jack Mack
jackmack2000de at yahoo.de
Tue Dec 21 10:28:53 CET 2010
Hi all,
I'm using Qt 4.7.1 on windows (VS2008).
I want to use QTcpSocket to implement a TCP client which connects to a TCP server.
I thought it's asynchronous and does not blocks the GUI.
There are "two general approaches" described: http://doc.qt.nokia.com/4.7/network-fortuneclient.html
I don't understand what they mean with "asynchronous". I have implemented a reconnect function because if the connection aborts the client have to try to reconnect itself.
Is the server not running the QTcpSocket::connectToHost() blocks the GUI for a short time.
You can test it with Qt example fortune client.
1) Start the fortune client and enter a free port number
2) Press "Get fortune" and then moving the fortune clients window.
Result:
After a short time the window is blocking first time (this is during connectToHost() is not able to establish the connection!).
The second blocking is done by connected slot displayError() to signal
QAbstractSocket::error(). The displayError() calls a blocking
QMessageBox(). That's ok.
I think QTcpSocket is not realy asynchronous! I understand
"asynchronous" is when you can moving the window without any freeze
moments.
Any suggestions?
How I can solve that problem (blocking GUI)?
Example please because a lot of answers in other forums means: using threads, could not be, you are doing something wrong. The authors of that answers didn't run the fortune client example! ;-)
Trying to use QThreads is my next way but I think it's not easy. The threaded fortune server example shows only how the server handles incoming QTcpSocket per thread.
Regards
jackmack
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101221/60c22753/attachment.html
More information about the Qt-interest-old
mailing list