Problem with DNS lookup

  • I have a set of (non-Qt) applications written in C and C++. I use standard TCP sockets -- server and clients, to send and receive the data. I have simple TcpClient and TcpServer classes so I'm not re-writing code. Everything works fine. But I was then asked to add the client to a Qt appliction. Now, my TCP client fails to initialize in Qt (it compiles without error). In particular, the call to gethostbyname( "localhost") returns a null pointer. Looking through the documentation and examples, i can't find any references on how to resolve a host name outside of the QTcpSocket stuff, and I'd rather not have to recreate my socket. Any suggestions on how to resolve the host name in the Qt environment equivalent to gethostbyname()? BTW, I tested with "localhost" and still got a null pointer. If I am required (grumble) to us QTcpSocket, can anyone point me to a good example of creating a non-blocking Qt client that connects to a non-QT TCP server?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What error do you get ?

    In any case, you don't need QTcpSocket, QHostInfo is there for that.

    Qt's network stack is non blocking.

Log in to reply