获取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;
代码测速
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版本:编译时对应用程序的速度进行优化,使得程序在代码大小和运行速度上都是最优的。