PDA

View Full Version : How to change Linux system clock by Qt



wisconxing
5th September 2011, 08:43
Hello

I want to change set Linux's system clock, I ever tried QDateTime, but the setDate and setTime are not effect.

Thank you

wysota
5th September 2011, 09:04
Changing system date requires superuser privileges. Qt has no facilities to modify system date, as far as I know. You can call date through QProcess if you want. Maybe also some interface for modifying date and time is exposed in dbus.

stampede
5th September 2011, 09:05
I ever tried QDateTime, but the setDate and setTime are not effect.
From the documentation:

Sets the time part of this datetime to time.
Those are setters for the QDateTime object, not the system values. I think you will need to use system api. You can for example use QProcess to call "date" command on linux. More here: howto-set-date-time-from-linux-command-prompt/ (http://www.cyberciti.biz/faq/howto-set-date-time-from-linux-command-prompt/)

wisconxing
7th September 2011, 07:04
Thank you very much !