zl程序教程

您现在的位置是:首页 >  工具

当前栏目

Qt硬件序列号

Qt硬件 序列号
2023-09-14 09:05:11 时间

获取mac地址 

在pro工程中加入:QT += network

 

win.h文件

#ifndef WIN_H
#define WIN_H

#include <QWidget>
#include <QDebug>
#include <QNetworkInterface>  //导入头文件

class Win : public QWidget
{
    Q_OBJECT

public:
    Win(QWidget *parent = nullptr);
    ~Win();

    QStringList get_mac();//获取mac函数

};
#endif // WIN_H

win.cpp文件

#include "win.h"

Win::Win(QWidget *parent)
    : QWidget(parent)
{
    this->resize(300,200);
    QStringList maclist=get_mac();
    qDebug()<<maclist[0];

}

Win::~Win()
{
}

QStringList Win::get_mac()
{
QStringList mac_list;
QString strMac;
QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
//返回一个在主机上找到的所有网络接口的列表。如果查找失败,则返回一个0个元素的列表
for (int i=0; i<ifaces.count(); i++)
    {
        QNetworkInterface iface = ifaces.at(i);

        //过滤掉本地回环地址、没有开启的地址
        if (iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack))
        {
            //过滤掉虚拟地址
            if (!(iface.humanReadableName().contains("VMware",Qt::CaseInsensitive)))
            {
                strMac = iface.hardwareAddress();
                mac_list.append(strMac);
            }
        }
    }
    return mac_list;

}

 

硬件信息

需要:#include <QProcess>

win.cpp

#include "win.h"

Win::Win(QWidget *parent)
    : QWidget(parent)
{
    this->resize(300,200);

    QString str=getWMIC("wmic cpu get processorid");  //查询cpu序列号
    str=getWMIC("wmic baseboard get serialnumber");  //查询主板序列号
    str=getWMIC("wmic bios get serialnumber");    //查询BIOS序列号
    str=getWMIC("wmic diskdrive get serialnumber");  //查看硬盘
    str=getWMIC("wmic cpu get Name");                //获取cpu名称
    //"Intel(R) Core(TM) i7-3537U CPU @ 2.00GHz"

    str=getWMIC("wmic cpu get NumberOfCores");  //获取cpu核心数
    //"2"
    str=getWMIC("wmic cpu get NumberOfLogicalProcessors"); //获取cpu线程数
    //"4"


    qDebug()<<str;
}

Win::~Win()
{
}

QString Win::getWMIC(const QString &cmd)  //获取硬件信息函数
{
    QProcess p;
        p.start(cmd);
        p.waitForFinished();
        QString result = QString::fromLocal8Bit(p.readAllStandardOutput());
        QStringList list = cmd.split(" ");
        result = result.remove(list.last(), Qt::CaseInsensitive);
        result = result.replace("\r", "");
        result = result.replace("\n", "");
        result = result.simplified();
        return result;
}

本文福利,费领取Qt开发学习资料包、技术视频,内容包括(C++语言基础,Qt编程入门,QT信号与槽机制,QT界面开发-图像绘制,QT网络,QT数据库编程,QT项目实战,QSS,OpenCV,Quick模块,面试题等等)↓↓↓↓↓↓见下面↓↓文章底部点击费领取↓↓