Hi
The Qt doc says that QAbstractSocket::waitForConnected(-1) will wait until the connection is made.But it returns immediately.The following program shows the problem.
#include <QtCore>
#include <QtNetwork>
int main(int argc, char *argv[])
{
socket.
connectToHost(QString("127.0.0.1"),
8888);
if(socket.waitForConnected(-1))
qDebug()<<"wait connected";
qDebug()<<socket.state();
return a.exec();
}
#include <QtCore>
#include <QtNetwork>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTcpSocket socket;
socket.connectToHost(QString("127.0.0.1"), 8888);
if(socket.waitForConnected(-1))
qDebug()<<"wait connected";
qDebug()<<socket.state();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
In the above program the if condition is supposed to return always true.But it always returns immediately and the socket state is in unconnected state.
Bookmarks