Solved QT4 - Using host/PC name in QUrl
-
Hello,
I am sending REST request to server. Using QUrl I am formatting the request.
QUrl requestedUrl; requestedUrl.setHost("169.29.2.101"); requestedUrl.setPort(8081); requestedUrl.setPath("/ticket/services/config"); requestedUrl.setScheme("http"); QNetworkRequest req(requestedUrl); reply = qnam.get(req);
The above code works correctly. I would like to replace IP address with host/PC name. Both client and server are running in same domain network so no proxy issue.
requestedUrl.setHost("169.29.2.101"); TO requestedUrl.setHost("EAGLE-1");
Should I use QHostinfo to get IP from host name or Is there way to specify it in QUrl?
Thanks,
Hari -
@hariprasasth said in QT4 - Using host/PC name in QUrl:
Is there way to specify it in QUrl?
Yes, you can specify the hostname in the URL. And you can also use QHostInfo class for host names lookup & resolution, but everything ends up being a question of having a working name resolution service in the underlying OS being it by means of a DNS server or by manually configuring host name files (i.e. /etc/hosts in *nix)
-
@hariprasasth said in QT4 - Using host/PC name in QUrl:
Is there way to specify it in QUrl?
Yes, you can specify the hostname in the URL. And you can also use QHostInfo class for host names lookup & resolution, but everything ends up being a question of having a working name resolution service in the underlying OS being it by means of a DNS server or by manually configuring host name files (i.e. /etc/hosts in *nix)