Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Some details of using QHostInfo::lookupHost



  • Hi!
    I want to know how to check IP or DNS I set is ok. But I have some questions about lookupHost().

    1. If I set QHostInfo::lookupHost("192.168.1.1",this, SLOT(receiver()) , does it run continuously or just check once?
    2. If I set as follows ,will they interfere each other?
      QHostInfo::lookupHost("192.168.1.1",this, SLOT(receiver1());
      QHostInfo::lookupHost("192.168.1.2",this, SLOT(receiver2());
    
    1. How about check DNS is ok if in local area network?
      e.g. QHostInfo::lookupHost("8.8.8.8",this, SLOT(receiver2()).

    Regards.
    Mihan


  • Lifetime Qt Champion

    Hi,

    1. AFAIK, it will search once. It would not make sense to spam a DNS with the same query continuously.

    2. No, they will not interfere. Note that the order in which you will ge the results is not guaranteed. See the method documentation.

    3. I'm not sure I'm following you on that one.



  • Thanks @SGaist
    Normally, If I close the DHCP, I must set IP, gateway, netmask and DNS so that machine can go online, rigth?
    So The third question is that if the IP is rigth but the DNS is wrong, can it detect?
    e.g.
    IP: 192.168.1.1 (√)
    DNS: 8.8.7.8 (not exist)
    then I use QHostInfo::lookupHost("8.8.7.8",this, SLOT(receiver2()), can it return the error.

    BTY, If I want to make a real time check for the local area network, must I make a timer to run this function? Or you can give me some suggest, thank you.

    Regards
    Mihan


  • Lifetime Qt Champion

    If you don't have a DNS, you won't be able to have name resolution so you'll have to use only IP addresses to access resources you are interested in.

    QHostInfo has an error method.



  • @Mihan said in Some details of using QHostInfo::lookupHost:

    then I use QHostInfo::lookupHost("8.8.7.8",this, SLOT(receiver2()), can it return the error.

    Have you checked the code snippet from QHostInfo::lookupHost() documentation?
    You have an example there how to check for error...


Log in to reply