使用qt函数获取网络时间
现在Qt Project Setting中的Qt Modules勾选NetWork,再导入头文件我也忘了叫什么了
QStringList net_time;
QTcpSocket *socket = new QTcpSocket();
socket->connectToHost("time.windows.com", );
//connectToHost(url,port) //现在用这个不稳定,暂时没找到好的替代
if (socket->waitForConnected())
{
if (socket->waitForReadyRead())
{
QString str(socket->readAll());
str = str.trimmed();
str = str.section(" ", , );
qDebug() <<"str :"<< str;
}
else
{
//else
}
}
socket->close();
delete socket;