Qt World Summit: Register Today!

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


  • Lifetime Qt Champion


    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?
    IP: (√)
    DNS: (not exist)
    then I use QHostInfo::lookupHost("",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.


  • 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("",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