Address through the IP address, is to query the database, if you do a database workload is relatively large, so on the Internet to find a query IP address URL, by calling this URL query to achieve, but this has some drawbacks, if there is no network or the URL is not available, you can not query. The specific code is as follows:
Qeventloop Loop;
Qnetworkaccessmanager Manager;
Qnetworkreply *preply = Manager.get (Qnetworkrequest (Qurl ("http://www.ip38.com/")); Http://www.ip38.com/index.php?ip= your IP
Connect (preply, SIGNAL (finished ()), &loop, SLOT (Quit ()));
Loop.exec ();
Qbytearray byte = Preply->readall ();
QString strtemp;
strtemp = Strtemp.fromlocal8bit (Byte.data ());
int nstartindex = Strtemp.indexof ("<div id=\" ipadcode\ "style=\" display:none\ ">");
if (nstartindex >= 0)
{
Nstartindex + = strlen ("<div id=\" ipadcode\ "style=\" display:none\ ">");
int nendindex = Strtemp.indexof ("</div>", Nstartindex);
if (Nendindex > Nstartindex)
{
QString strresult = strtemp.mid (Nstartindex + 1, nendindex-nstartindex-1);
}
}
The above ip38 site sometimes fails and can be used when it fails: http://iframe.ip138.com/ic.asp
http://blog.csdn.net/itjobtxq/article/details/10497261
QT locates addresses by IP address (get data by using the Fetch method)