改进方法
parent
c6ea1dd735
commit
caff8c692f
|
@ -56,6 +56,11 @@ void NtpClient::sendData()
|
||||||
udpSocket->write(timeRequest);
|
udpSocket->write(timeRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NtpClient::setTime_t(uint secsSince1Jan1970UTC)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void NtpClient::readData()
|
void NtpClient::readData()
|
||||||
{
|
{
|
||||||
QByteArray newTime;
|
QByteArray newTime;
|
||||||
|
@ -79,13 +84,15 @@ void NtpClient::readData()
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime dateTime;
|
QDateTime dateTime;
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
uint secs = seconds - epoch.secsTo(unixStart);
|
||||||
dateTime.setTime_t(seconds - epoch.secsTo(unixStart));
|
//两个方法二选一由于Qt6移除了setTime_t方法所以要自己计算
|
||||||
#endif
|
//dateTime.setTime_t(secs);
|
||||||
|
dateTime.setDate(QDate(1970, 1, 1).addDays(secs / 86400));
|
||||||
|
dateTime.setTime(QTime().addSecs(secs % 86400 + (8 * 60 * 60)));
|
||||||
|
|
||||||
#ifdef __arm__
|
#ifdef __arm__
|
||||||
#ifdef arma9
|
#ifdef arma9
|
||||||
dateTime = dateTime.addSecs(60 * 60 * 8);
|
dateTime = dateTime.addSecs(8 * 60 * 60);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
udpSocket->disconnectFromHost();
|
udpSocket->disconnectFromHost();
|
||||||
|
|
|
@ -31,6 +31,7 @@ private:
|
||||||
private slots:
|
private slots:
|
||||||
void readData();
|
void readData();
|
||||||
void sendData();
|
void sendData();
|
||||||
|
void setTime_t(uint secsSince1Jan1970UTC);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//收到时间返回
|
//收到时间返回
|
||||||
|
|
Loading…
Reference in New Issue