Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. (SOLVED)How To Change Date and Time in linux system based from Qt Based Application
Forum Update on Monday, May 27th 2025

(SOLVED)How To Change Date and Time in linux system based from Qt Based Application

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 19.8k Views
  • 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.
  • P Offline
    P Offline
    praveen0991kr
    wrote on 24 Aug 2013, 12:33 last edited by
    #1

    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

    1 Reply Last reply
    0
    • C Online
      C Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on 24 Aug 2013, 12:50 last edited by
      #2

      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.

      1 Reply Last reply
      1
      • K Offline
        K Offline
        koahnig
        wrote on 24 Aug 2013, 13:00 last edited by
        #3

        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.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • P Offline
          P Offline
          praveen0991kr
          wrote on 24 Aug 2013, 23:34 last edited by
          #4

          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

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on 25 Aug 2013, 15:49 last edited by
            #5

            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

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0
            • H Offline
              H Offline
              houmingc
              wrote on 17 Nov 2014, 07:22 last edited by
              #6

              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.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                praveen0991kr
                wrote on 17 Nov 2014, 16:00 last edited by
                #7

                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 ;

                1. System Clock;
                  date command
                2. Hardware Clock;
                  hwclock command

                it does require sudo command;

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  houmingc
                  wrote on 18 Nov 2014, 01:08 last edited by
                  #8

                  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

                  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