QT的waitForConnected(3000)的等待时间问题
在QT的Tcp客户端程序里我的客服端连接服务器时,若不能连上服务器,则设了下面的等待时间,
m_socket.abort();
m_socket.connectToHost(m_server,m_port);
int time1=getCurrentTime();//获得微秒时间的函数
if(!m_socket.waitForConnected(50000))
{
int time2=getCurrentTime();
int time3=time2-time1;
qDebug()<<"time3:"<<time3;
return false;
}
这里waitForConnected应该等待了5s,但是我使用时打印出的时间不是5秒,这是什么原因呢?
我若想我的客服端阻塞时间设为5s,若不能连上服务器,就退出连接,有什么其他的实现方式吗?