您的位置:首页 > 编程语言 > Qt开发

周报——QT可设置系统时间

2014-10-17 20:50 856 查看
昵称:cmj 日期:2014年10月10日—2014年10月17日

1、本周已完成任务:可设置系统时间

2、本周未完成任务:qt界面在显示屏的显示

3、下周计划:(1)、继续解决qt在cvbs上的显示问题 (2)、所要实现的功能需要各个模块配合

4、关键键技术点说明:

4.1hi_rtc驱动源码:

static long hi_rtc_ioctl(struct file *file,
unsigned int cmd,
unsigned long arg)
{
unsigned long flags;
int ret;

rtc_time_t time;
reg_data_t reg_info;
reg_temp_mode_t temp_mode;

switch (cmd)
{
...
...
case HI_RTC_RD_TIME:		//读取rtc时间
<span style="white-space:pre">		</span>HI_MSG("HI_RTC_RD_TIME");
hirtc_get_time(&time);
ret = copy_to_user((void *)arg, &time, sizeof(time));
if (ret) {
return -EFAULT;
}
break;
case HI_RTC_SET_TIME:
HI_MSG("HI_RTC_SET_TIME");
ret = copy_from_user(&time,
(struct rtc_time_t *) arg,
sizeof(time));
if (ret) {
return -EFAULT;
}
hirtc_set_time(time);
break;

...
default:
return -EINVAL;
}

return 0;
}
typedef struct {
unsigned int  year;
unsigned int  month;
unsigned int  date;
unsigned int  hour;
unsigned int  minute;
unsigned int  second;
unsigned int  weekday;
} rtc_time_t;
#define HI_RTC_RD_TIME  _IOR('p', 0x09,  rtc_time_t)
#define HI_RTC_SET_TIME  _IOW('p', 0x0a,  rtc_time_t)
qt程序
<P>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "hi_rtc.h"
#include <fcntl.h>
#include <sys/ioctl.h>
#include <QFile>
#include <QDebug>
#include <QDateTime>
static int fb;//静态设备号													MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}																MainWindow::~MainWindow()
{
    delete ui;
}																void MainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}																void MainWindow::settime() //设置rtc时间
{
    rtc_time_t tm;
    tm.year = 2014;
    tm.month = 10;
    tm.date = 17;
    tm.hour = 13;
    tm.minute = 13;
    tm.second = 00;
    tm.weekday =0;
    QFile f("/dev/hi_rtc");//定义led驱动文件
    if (f.exists())//如果文件存在
    {
        fb = open("/dev/hi_rtc", QIODevice::ReadWrite);//读写方式打开文件
        if (fb < 0)//打开驱动文件错误
        {
            perror("open device leds fail");//输入错误信息
             //  return ;//返回
        }
    }
    ioctl(fb, HI_RTC_SET_TIME, &tm);
    ::close(fb);														}
void MainWindow::gettime()//读取RTC时间
{
    rtc_time_t tm;
    QFile f("/dev/hi_rtc");//定义led驱动文件
    qDebug()<<1;
    if (f.exists())//如果文件存在
    {
        fb = open("/dev/hi_rtc", QIODevice::ReadWrite);//读写方式打开文件
        qDebug()<<2;
        if (fb < 0)//打开驱动文件错误
        {
            qDebug()<<3;
            perror("open device leds fail");//输入错误信息
             //  return ;//返回
        }
    }
    ioctl(fb, HI_RTC_RD_TIME, &tm);//读取rtc时间
    qDebug()<<tm.year<<tm.month<<tm.date<<tm.hour<<tm.minute<<tm.second;
    ::close(fb);
}																void MainWindow::setsystime() //设置系统时间
{
    QString time;
    time = "date 010101012000";
    system(time.toLatin1().data()); //.toLatin1().data()作用是将QString转char* ;
   // system("date 010101012000");
}																void MainWindow::getsystime() //获得系统时间
{
    QDateTime time = QDateTime::currentDateTime();//获取系统现在的时间
    QString str = time.toString("yyyy-MM-dd hh:mm:ss ddd"); //设置显示格式
    qDebug()<<str;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: