Planned maintenance has been done but it did not solve the problem. So work will continue on this and a new time for trying updates will be announced asap.

NTP Client library

  • Can someone suggest me a cross platform (Linux - Windows) library to have the ntp time from a server?

  • I have bring up this synchronized function that can be used inside a thread.

    bool GetNTPDateTime(QDateTime &DateTime, QString Server, int Socket) {
        bool Result= false;
        QHostInfo HostInfo= QHostInfo::fromName(Server);
        if (HostInfo.addresses().length()> 0) {
            QUdpSocket *UdpSocket= new QUdpSocket(); {
                UdpSocket->connectToHost(QHostAddress(HostInfo.addresses().at(0)), Socket);
                char Message[48]= {010, 0, 0, 0, 0, 0, 0, 0, 0};
                if (UdpSocket->writeDatagram(Message, sizeof(Message), QHostAddress(HostInfo.addresses().at(0)), Socket)== sizeof(Message)) {
                    if (UdpSocket->waitForReadyRead()) {
                        while (UdpSocket->hasPendingDatagrams()) {
                            QByteArray QBABufferIn= UdpSocket->readAll();
                            if (QBABufferIn.size()== 48) {
                                int count= 40;
                                unsigned long DateTimeIn= uchar( (uchar( 1)) << 8)+ (uchar( 2)) << 16)+ (uchar( 3)) << 24);
                                long tmit= ntohl((time_t)DateTimeIn);
                                tmit-= 2208988800U;
                                DateTime= QDateTime::fromTime_t(tmit);
                                Result= true;
                delete UdpSocket;
        return Result;

    What about it? I hope to do not have problem with it at the customers.

  • @mrdebug

    looks like you have a couple of paranthesis too much (see around delete UdpSocket). If it is sufficient for your purpose it is fine.

Log in to reply