Qt 域名转成IP

#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <arpa/inet.h>
struct
hostent *h; QByteArray ba = ui->lineEdit->text().toLatin1(); h = gethostbyname(ba.data()); if(h == NULL) { qDebug()<<"get hostbyname error!"; exit(1); } struct in_addr *in=(in_addr *)h->h_addr; char *ch = inet_ntoa(*in); QString str = QString(QLatin1String(ch)); qDebug()<<"IP Address:"<<str; ui->lineEdit_2->setText(str);
原文地址:https://www.cnblogs.com/wiessharling/p/3650982.html