From caff8c692f5ed57b95b8121f288cdaafd4df7f09 Mon Sep 17 00:00:00 2001 From: feiyangqingyun Date: Sun, 30 May 2021 17:33:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ntpclient/ntpclient.cpp | 15 +++++++++++---- ntpclient/ntpclient.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ntpclient/ntpclient.cpp b/ntpclient/ntpclient.cpp index c87dda5..ff35b03 100644 --- a/ntpclient/ntpclient.cpp +++ b/ntpclient/ntpclient.cpp @@ -56,6 +56,11 @@ void NtpClient::sendData() udpSocket->write(timeRequest); } +void NtpClient::setTime_t(uint secsSince1Jan1970UTC) +{ + +} + void NtpClient::readData() { QByteArray newTime; @@ -79,13 +84,15 @@ void NtpClient::readData() } QDateTime dateTime; -#if (QT_VERSION < QT_VERSION_CHECK(6,0,0)) - dateTime.setTime_t(seconds - epoch.secsTo(unixStart)); -#endif + uint secs = seconds - epoch.secsTo(unixStart); + //两个方法二选一由于Qt6移除了setTime_t方法所以要自己计算 + //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 arma9 - dateTime = dateTime.addSecs(60 * 60 * 8); + dateTime = dateTime.addSecs(8 * 60 * 60); #endif #endif udpSocket->disconnectFromHost(); diff --git a/ntpclient/ntpclient.h b/ntpclient/ntpclient.h index f270b03..f8c06d2 100644 --- a/ntpclient/ntpclient.h +++ b/ntpclient/ntpclient.h @@ -31,6 +31,7 @@ private: private slots: void readData(); void sendData(); + void setTime_t(uint secsSince1Jan1970UTC); signals: //收到时间返回