// 涉及到網絡模塊時記得在工程問題,加上:
// 並且根據相應提示,添加相應的頭文件:#include <QtNetwork>
- // 獲得ip地址
- QString getIpAdress()
- {
- QString localIPAddress = ”“;
- QList <QHostAddress>listAddress = QNetworkInterface::allAddresses();
- for(int j = 0; j < listAddress.size(); j++){
- if(!listAddress.at(j).isNull()
- && listAddress.at(j).protocol() == QAbstractSocket::IPv4Protocol
- && listAddress.at(j) != QHostAddress::LocalHost){
- localIPAddress = listAddress.at(j).toString();
- return localIPAddress;
- }
- }
- return localIPAddress;
- }
// 獲得ip地址
QString getIpAdress()
{
QString localIPAddress = "";
QList <QHostAddress>listAddress = QNetworkInterface::allAddresses();
for(int j = 0; j < listAddress.size(); j++){
if(!listAddress.at(j).isNull()
&& listAddress.at(j).protocol() == QAbstractSocket::IPv4Protocol
&& listAddress.at(j) != QHostAddress::LocalHost){
localIPAddress = listAddress.at(j).toString();
return localIPAddress;
}
}
return localIPAddress;
}
- //獲得MAC地址
- QStringUSBMainUI::getMACAdress()
- {
- QList<QNetworkInterface> NetList;//網卡鏈表
- int NetCount = 0;//網卡個數
- int Neti=0;
- QNetworkInterface thisNet;//所要使用的網卡
- NetList = QNetworkInterface::allInterfaces();//獲取所有網卡信息
- NetCount = NetList.count();//統計網卡個數
- for(Neti = 0; Neti < NetCount; Neti++){//遍歷所有網卡
- if( NetList[Neti].isValid() ){//判斷該網卡是否是合法
- thisNet = NetList[Neti];//將該網卡置爲當前網卡
- break;
- }
- }
- return(thisNet.hardwareAddress());//獲取該網卡的MAC
- }
//獲得MAC地址
QStringUSBMainUI::getMACAdress()
{
QList<QNetworkInterface> NetList;//網卡鏈表
int NetCount = 0;//網卡個數
int Neti=0;
QNetworkInterface thisNet;//所要使用的網卡
NetList = QNetworkInterface::allInterfaces();//獲取所有網卡信息
NetCount = NetList.count();//統計網卡個數
for(Neti = 0; Neti < NetCount; Neti++){//遍歷所有網卡
if( NetList[Neti].isValid() ){//判斷該網卡是否是合法
thisNet = NetList[Neti];//將該網卡置爲當前網卡
break;
}
}
return(thisNet.hardwareAddress());//獲取該網卡的MAC
}
- // 獲得用戶名
- QString getUserName()
- {
- QString userName = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
- userName = userName.section(“/”, -1, -1);
- return userName;
- }
// 獲得用戶名
QString getUserName()
{
QString userName = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
userName = userName.section("/", -1, -1);
return userName;
}
- // 獲得機器名字
- QString getMachineName()
- {
- QString localHostName = QHostInfo::localHostName();
- return localHostName;
- }
// 獲得機器名字
QString getMachineName()
{
QString localHostName = QHostInfo::localHostName();
return localHostName;
}
//轉 秋葉原 && Mike || 麥克