9月19日学习记录

获取Windows系统的UUID

cmd.exe中执行wmic csproduct get uuid

cpp 复制代码
    QProcess p(0);
    p.start("cmd",QStringList()<<"/c"<<"wmic csproduct get uuid");
    p.waitForStarted();
    p.waitForFinished();
    QString strTemp=QString::fromLocal8Bit(p.readAllStandardOutput());
    QStringList list=strTemp.split('\n');
    QString str=list.at(1);
    str=str.simplified();
    qDebug()<<str;

获取Windows系统的CPUID

wmic cpu get processorid

cpp 复制代码
    QProcess p(0);
    p.start("cmd",QStringList()<<"/c"<<"wmic cpu get processorid");
    p.waitForStarted();
    p.waitForFinished();
    QString strTemp=QString::fromLocal8Bit(p.readAllStandardOutput());
    QStringList list=strTemp.split('\n');
    QString str=list.at(1);
    str=str.simplified();
    qDebug()<<str;

获取系统当前时间

qt -- 获取当前时间 QDateTime、QTime、QDate_currentdatetime_cc_rong的博客-CSDN博客

cpp 复制代码
    QDateTime datetime=QDateTime::currentDateTime();
    QString str=datetime.toString("yyyy-MM-dd hh:mm:ss");
    qDebug()<<str;

目标:保存程序第一次运行的时间戳。

先在release目录下创建time.ini,内容如下(我用的release版本):

cpp 复制代码
[MAIN]
is_first=true
first_using_time=
cpp 复制代码
    QSettings* settings = new QSettings("time.ini", QSettings::IniFormat);
    settings->beginGroup("MAIN");
    bool is_first=settings->value("is_first").toBool();
    if(is_first){
        QDateTime datetime=QDateTime::currentDateTime();
        QString str=datetime.toString("yyyy-MM-dd hh:mm:ss");
        settings->setValue("is_first",false);
        settings->setValue("first_using_time",str);
    }
    settings->endGroup();
    delete settings;

代码测速

QElapsedTimer-CSDN博客

cpp 复制代码
    QElapsedTimer timer;
    if(timer.isValid()){
        qDebug()<<"QElapsedTimer is valid before starting";
    }
    else{
        qDebug()<<"QElapsedTimer is invalid before starting";
    }
    timer.start();

    if (timer.isValid()) {
        qDebug() << "QElapsedTimer is valid when started";
    } else {
        qDebug() << "QElapsedTimer is invalid when started";
    }

    for (int i = 0; i < 200000000; i++);

    qint64 endTime = timer.nsecsElapsed();
    qDebug() << "Time elapsed:" << endTime << "ns";

debug: 460615800 ns

release:873700 ns

release版本:编译时对应用程序的速度进行优化,使得程序在代码大小和运行速度上都是最优的。

相关推荐
软萌萌的122 分钟前
Python零基础从入门到精通详细教程-数据类型
开发语言·windows·python
东北赵四29 分钟前
关于Java泛型的知识点及其相关面试题
java·windows·python
邱邱玩编程2 小时前
环境变量速切脚本【Windows】
windows
upgrador4 小时前
桌面应用开发:Electron 与 NSIS 的关系、打包流程及 Windows 本地构建实战
javascript·windows·electron
脚踏实地皮皮晨5 小时前
003002004_WPF Panel 基类 官方类定义
开发语言·windows·算法·c#·wpf·visual studio
sukalot5 小时前
windows网络适配器驱动开发-双 STA 连接(下)
windows·驱动开发·stm32
IT小盘15 小时前
12-Prompt不等于一句话-System-User-Context三层结构
java·windows·prompt
PieroPc20 小时前
Python 写的 Windows凭据添加工具 第二版 解决Win11 23H2, 25H2,26H1,共享文件和打印 一部份问题,不是全部!
开发语言·windows·python
feasibility.1 天前
wsl安装Ubuntu方法(含网络不稳定处理)
linux·运维·windows·ubuntu
我命由我123451 天前
Windows 操作系统 - 符号链接
linux·运维·windows·系统架构·操作系统·运维开发·系统