1.在构造函数中获取物理地址
QList<QNetworkInterface> list = QNetworkInterface::allInterfaces();
foreach(QNetworkInterface interface1, list) //遍历list中符合interface1.humanReadableName() == QString::fromLocal8Bit("本地连接")条件的IP地址
{
if (interface1.humanReadableName() == QString::fromLocal8Bit("本地连接"))
{
ui.lineEdit->setText(interface1.hardwareAddress()); //将该地址写入编辑框中
}
}
connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(copyAddress()));
2.新建一个槽函数,将获取到的物理地址复制到该剪切板中
void GetHardware::copyAddress()
{