qt获取网卡地址、主机名

mac.pro

#-------------------------------------------------
#
# Project created by QtCreator 2013-06-06T10:39:54
#
#-------------------------------------------------

QT       += core
QT       += network


QT       -= gui

TARGET = mac
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app


SOURCES += main.cpp
main.cpp

#include <QCoreApplication>
#include <QtNetwork/QNetworkInterface>
#include <QHostInfo>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QList<QNetworkInterface> list = QNetworkInterface::allInterfaces();
    foreach (QNetworkInterface i, list) {
        qDebug() << i;
    }
    
    QString localHostName = QHostInfo::localHostName();
    qDebug() << localHostName;

    return a.exec();
}

你可能感兴趣的:(hostname,mac,qt)