首先 *.pro 文件添加network,否则会出现找不到network相关头文件
QT += core gui
QT += network
若添加后依旧找不到,删除编译生成的文件,重新编译
net.h 头文件
#ifndef NET_H
#define NET_H
#include <QWidget>
#include <QtDebug>
#include <QHostInfo>
#include <QHostAddress>
#include <QNetworkInterface>
#include <QNetworkAddressEntry>
#define MYDEBUG qDebug() << "[" <<__FILE__ <<":"<<__FUNCTION__<<":"<<__LINE__ <<"]"
class Net : public QWidget
{
Q_OBJECT
public:
Net(QWidget *parent = 0);
~Net();
public:
QString machineName;
QList<QHostAddress> list_hostaddress;
QList<QNetworkInterface> list_interface;
QList<QNetworkAddressEntry> list_networ