babu198649
24th January 2009, 08:33
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[])
{
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();
}
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.
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[])
{
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();
}
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.