2个回答
展开全部
这个比较简单的哦,我给你讲步骤吧,
第一步,创建一个dateTimeEdit,第二步,将其connect到一个函数上,第三部,提取它的QDateTime,然后利用下面的函数就可以了,它是基于shell命令的:
void moreidDialog::slot_save_time_key()
{
QDateTime time;
QString str = txt_time->text();
//判断格式是否正确
if (str.count(".") != 4)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
int i = 0,j = 0;
i = str.indexOf(".");
QString year = str.mid(0,i);
j = str.indexOf(".",i + 1);
QString month = str.mid(i + 1,j - i - 1);
i = j;
j = str.indexOf(".",i + 1);
QString day = str.mid(i + 1,j - i - 1);
i = j;
j = str.indexOf(".",i + 1);
QString hour = str.mid(i + 1,j - i - 1);
i = j;
j = str.indexOf(".",i + 1);
QString min = str.mid(i + 1,j - i - 1);
bool ok = false;
year.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
month.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
day.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
hour.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
min.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
str = "date -s " + month + "/" + day + "/" + year;
system(str.toLatin1().data());
str = "date -s " + hour + ":" + min + ":" + "00";
system(str.toLatin1().data());
//强制写入到CMOS
system("clock -w");
}
第一步,创建一个dateTimeEdit,第二步,将其connect到一个函数上,第三部,提取它的QDateTime,然后利用下面的函数就可以了,它是基于shell命令的:
void moreidDialog::slot_save_time_key()
{
QDateTime time;
QString str = txt_time->text();
//判断格式是否正确
if (str.count(".") != 4)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
int i = 0,j = 0;
i = str.indexOf(".");
QString year = str.mid(0,i);
j = str.indexOf(".",i + 1);
QString month = str.mid(i + 1,j - i - 1);
i = j;
j = str.indexOf(".",i + 1);
QString day = str.mid(i + 1,j - i - 1);
i = j;
j = str.indexOf(".",i + 1);
QString hour = str.mid(i + 1,j - i - 1);
i = j;
j = str.indexOf(".",i + 1);
QString min = str.mid(i + 1,j - i - 1);
bool ok = false;
year.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
month.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
day.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
hour.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
min.toInt(&ok);
if (ok == false)
{
txt_time->setText(tr("ge shi cuo wu"));
return;
}
str = "date -s " + month + "/" + day + "/" + year;
system(str.toLatin1().data());
str = "date -s " + hour + ":" + min + ":" + "00";
system(str.toLatin1().data());
//强制写入到CMOS
system("clock -w");
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询