Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Setting the Date

Setting the Date

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sos1
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sos1
        wrote on last edited by
        #3

        OK.

        Thanks

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved