(SOLVED)How To Change Date and Time in linux system based from Qt Based Application
-
wrote on 24 Aug 2013, 12:33 last edited by
Dear ,
I am trying to to change date and time of system from qt application but there is no effect from QDate and QTime class ;
when I am access currentDate() and currentTime() it access system time.Praveen
-
QDate and QTime are not used to change any system settings. They are just data formats to hold information about date and time.
What you need is a OS specific feature. For Windows it's a "SetLocalTime":http://msdn.microsoft.com/en-us/library/ms724936.aspx API. On Linux there's a "date":http://linux.die.net/man/1/date command which you can call with "QProcess":http://qt-project.org/doc/qt-5.1/qtcore/qprocess.html .
You might of course need to run your app with enough access privileges to be able to do that. -
wrote on 24 Aug 2013, 13:00 last edited by
welcome to devnet
The static methods "currentDate":http://qt-project.org/doc/qt-5.0/qtcore/qdate.html#currentDate and "currentTime":http://qt-project.org/doc/qt-5.0/qtcore/qtime.html#currentTime read only
You may use "setDate":http://qt-project.org/doc/qt-5.0/qtcore/qdate.html#setDate and "setTime":http://qt-project.org/doc/qt-5.0/qtcore/qtime.html#setHMS but AFAIK those will not change the system clock permanently either.
-
wrote on 24 Aug 2013, 23:34 last edited by
I am using Linux environment Based device. Using @ setDate @ and @ setTime @ also I am i am not able to set my clock when I use @ currentTime @ and current date it is the system time not that what i have set through @ setTime and setDate @
@Chris
If it can be done with Qprocess pls tell me how
Did I can make a object for the same to access or there is specific commands to set and read current time as per we have set.i have gone through the link as per mentioned on http://www.qtcentre.org/archive/index.php/t-44384.html
http://www.cyberciti.biz/faq/howto-set-date-time-from-linux-command-prompt/but i want to access through program Qt application
-
wrote on 25 Aug 2013, 15:49 last edited by
As Chris confirmed it is not possible through Qt directly.
When using QProcess you basically use a standard command, a linux command in your case, to change the system clock. Like you would do on a terminal prompt. However, you will have to have the superuser rights.
With QProcess you can basically launch any command and application available on a system.
In addition to the links already provided, you may also check out the "QProcess documentation.":http://qt-project.org/doc/qt-5.0/qtcore/qprocess.html -
wrote on 17 Nov 2014, 07:22 last edited by
If there is ubuntu system header and source file (API downloadable), this is still achievable. Right?
The question is where to get the header and source file.Is there a method to input sudo password rather than wait for interactive command. is setuid, seteuid, setgid able to do the job.
-
wrote on 17 Nov 2014, 16:00 last edited by
Hello Frnds ,
Thanks for your replies ;
I am able to change the date and time as well :--) Yes thanks to koahhning for refering QProcess documentation it really helped ;QProcess allow to access command line or terminal to change the Date and Time In my case the Embedded device I am working on having kernal 3.2 and from command line I can able to change the date and time ;
- System Clock;
date command - Hardware Clock;
hwclock command
it does require sudo command;
- System Clock;
-
wrote on 18 Nov 2014, 01:08 last edited by
I found command chmod u+s hello will give the app root access.
http://stackoverflow.com/questions/6119254/how-to-run-a-script-with-root-authority-in-linux