QT locates addresses by IP address (get data by using the Fetch method)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.