Setting the Date



  • I'm trying to change the date on the BeagleBone, taking the date from QLineEdits on the UI.
    There are two problems:-

    1. It does not change the system time
    2. It won't write to the RTC chip.

    @void MainWindow::on_pbSet_clicked()
    {
    QDate date;
    QTime time;
    QString value,temp;

    if (date.setDate(QString(ui->le_year->text()).toInt(),
                 QString(ui->le_month->text()).toInt(),
                 QString(ui->le_day->text()).toInt() ) )
    {
        qDebug() << "Date Set OK! " << date.toString() ;
     }
    else
    {
        qDebug() << "Error in date set! " ;
    }
    
    time.setHMS(QString(ui->le_hour->text()).toInt(),
                QString(ui->le_minute->text()).toInt(),
                0,
                0);
    
    ui->le_year->setText(QString::number(date.year()));
    ui->le_month->setText(QString::number(date.month()));
    ui->le_day->setText(QString::number(date.day()));
    ui->le_hour->setText(QString::number(time.hour()));
    ui->le_minute->setText(QString::number(time.minute()));
    
    system&#40;"hwclock --utc --systohc"&#41;;
    

    }@

    On the first qDebug line "Date set OK", it correctly gives the date I changed to. But when I later refill the LineEdit boxes with the date, its the old date that is restored.

    What is my problem here?

    Regards,
    James


  • Lifetime Qt Champion

    Hi,

    QDate is not a system clock abstraction. You can get the time from the system but you can't set it (depending of the modification you might need root access)

    You have to use platform specific methods for that.



  • OK.

    Thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.