Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Trying to get Ntp client to work
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Trying to get Ntp client to work

Scheduled Pinned Locked Moved General and Desktop
ntpqudpsocket
17 Posts 3 Posters 9.9k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #6

    Finally solved.

    Stupid user error or misleading Qt doc. Whereever you want to blame this.

    QHostAddress is only valid for IP addresses. However, since no IP addresses are typically given for NTP servers, I had used names found in internet. RTFM carefully helps.

    Well, I did not see a point to check out QHostAddress carefully, because with QTcpSockets I am using a mix of host names and ip addresses without caring. The parameter list of connectToHost has also QHostAddress. However, the other method contains QString as parameter. After years of using successfully there was no reason ....

    QHostInfo has to be involved for resolving the lookup.

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      From what I can see you are trying to use the NTP reserved port (123), so you must have the credentials to do so. User available ports start at 1024

      K Offline
      K Offline
      koahnig
      wrote on last edited by koahnig
      #7

      @SGaist @mcosta
      123 is possible to use. See also above

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #8

        If I understand you correctly, the behavior of QHostAddress changed between two versions of Qt ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        K 1 Reply Last reply
        0
        • SGaistS SGaist

          If I understand you correctly, the behavior of QHostAddress changed between two versions of Qt ?

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #9

          @SGaist
          I am not sure about this. Also I am not sure when QHostAddress has been implemented first.

          Those prototype are available in QAbstractSocket

          connectToHost(const QString &, quint16, OpenMode, NetworkLayerProtocol);
          connectToHost(const QHostAddress &, quint16, OpenMode);
          

          I have started to use QTcpSocket in 2007 and I am using the same mechanism with host names and IP addresses. Being careful, it is obvious that I am using the first prototype. I have seen also the second prototype many times.
          When seeing the prototype using the ntp class, it was completely clear to me that the behaviour is identical to the behaviour of QTcpSocket. The "minor detail" of QHostAddress was overlooked. I saw no warning or anything. Therefore, I did not pay attention and looked in other areas where I did not have experience with.

          Finally I thought that I missed the obvious and started this thread. Unfortunately, I missed to add the section with the creation of the QHostAddress object by using the contructor QHostAddress::QHostAddress(const QString & address) with a host name.
          That would have given others the chance to point out my stupid mistake.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #10

            QHostAddress dates back to Qt 3 so it's a pretty old class

            So if I follow you correctly, you thought you were using the first one, while in practice the second one was called ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            K 1 Reply Last reply
            0
            • SGaistS SGaist

              QHostAddress dates back to Qt 3 so it's a pretty old class

              So if I follow you correctly, you thought you were using the first one, while in practice the second one was called ?

              K Offline
              K Offline
              koahnig
              wrote on last edited by
              #11

              @SGaist
              Basically yes. Simply running into the trap and did not pay attention.

              Vote the answer(s) that helped you to solve your issue(s)

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #12

                I'm surprised that it does an automatic conversion like that...

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                K 1 Reply Last reply
                0
                • SGaistS SGaist

                  I'm surprised that it does an automatic conversion like that...

                  K Offline
                  K Offline
                  koahnig
                  wrote on last edited by koahnig
                  #13

                  @SGaist said:

                  I'm surprised that it does an automatic conversion like that...

                  Just try HostAddress.pro

                  QT       += core network
                  QT       -= gui
                  TARGET = HostAddress
                  CONFIG   += console
                  CONFIG   -= app_bundle
                  TEMPLATE = app
                  SOURCES += main.cpp
                  

                  main.cpp:

                  #include <QCoreApplication>
                  #include <QHostAddress>
                  
                  int main(int argc, char *argv[])
                  {
                      QCoreApplication a(argc, argv);
                  
                      QHostAddress hadd ( "any.domain.com" );
                  
                      return a.exec();
                  }
                  

                  This does not tell you a thing. Clearly by reading the docs that is wrong and you have to look up the ip address and use a proper ip address.
                  However, the constructor does notice that the input is wrong. I would expect to see at least a message. Probably the reason is that the class is rooting back to Qt3.

                  Vote the answer(s) that helped you to solve your issue(s)

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #14

                    Hi,

                    In fact the constructor taking a string doesn't detect anything particular. However using setAddress would return false so it might be a better option currently

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    K 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      Hi,

                      In fact the constructor taking a string doesn't detect anything particular. However using setAddress would return false so it might be a better option currently

                      K Offline
                      K Offline
                      koahnig
                      wrote on last edited by
                      #15

                      @SGaist
                      You are right. Also when reading all the details in the documentation it becomes obvious.

                      My point is that this is not really consistent with error reporting in other sections of Qt. In my opinion Qt's beauty is because of the error reporting, which helps to avoid problems. For instance when using a non-existing signal in a connect or the parameters are not fitting one receives a message reporting the problem. Certainly when one is not checking the connect's return value, the information might be lost. However, when you start to check the return value with an assert it is very powerful and you see immediately your problem.

                      For consistency I would expect to obtain at least a direct warning, when a non-IP address is handed over. Compared to other really good things in Qt, this is rather sloppy and forms a trap.

                      Vote the answer(s) that helped you to solve your issue(s)

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #16

                        Just talked with one the network kings: you should use isNull before using your QHostAddress object, then you'll know for sure that you have a valid address.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        K 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          Just talked with one the network kings: you should use isNull before using your QHostAddress object, then you'll know for sure that you have a valid address.

                          K Offline
                          K Offline
                          koahnig
                          wrote on last edited by
                          #17

                          @SGaist

                          Thanks for following up. Certainly I will take care this next time. I guess I will remember.

                          Vote the answer(s) that helped you to solve your issue(s)

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved