我也是在网上找的,自己随便改了一下
六个lineEdit控件,每个控件输入日期时间,点击按钮触发函数可修改时间。
1 //一键修改系统时间
QString year = ui->lineEdit_9->text(); //年
QString month = ui->lineEdit_10->text(); //月
QString day = ui->lineEdit_11->text(); //日
QString hour = ui->lineEdit_12->text(); //时
QString min = ui->lineEdit_13->text(); //分
QString second = ui->lineEdit_14->text(); //秒
QString a = "date -s" + year + "/" + month + "/" + day;
QString b = "date -s" + hour + ":" + min + ":" + second;
char *ch;
QByteArray ba = a.toLatin1();
ch = ba.data();
char *ch_2;
QByteArray ba_2 = b.toLatin1();
ch_2 = ba_2.data();
system(ch);
system(ch_2);
//强制写入到CMOS
system("hwclock -w");