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. How to do something at some specified time

How to do something at some specified time

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.2k 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.
  • A Offline
    A Offline
    ARASHz4
    wrote on last edited by ARASHz4
    #1

    Hi i want do something at at some specified date & time like 2/15/2017 10:30:00 & 2/15/2017 11:30:00
    I want call a function at this times

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

      Hi,

      If you're on Linux then use a cron job to call your application/script/whatever you need.

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

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        If you're on Linux then use a cron job to call your application/script/whatever you need.

        A Offline
        A Offline
        ARASHz4
        wrote on last edited by
        #3

        @SGaist I want use cross platform way

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          like 2/15/2017 10:30:00

          int msecTo(const QDateTime& fromdt,const QDateTime& todt){
          return 
          fromdt.time().mSecTo(todt.time())+(
          fromdt.date().daysTo(todt.date())*24*60*60*1000
          );
          }
          const QDateTime target(QDate(2017,2,15),QTime(10,30,0));
          QTimer::singleShot(msecTo(QDateTime::currentDateTime(),target),[]()->void{qDebug("2/15/2017 10:30:00 and all's well!");});
          

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

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

            Just keep in mind that with the solution of @VRonin you have to ensure that your application has to be running at the time you want your function to be executed.

            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
            • VRoninV VRonin

              like 2/15/2017 10:30:00

              int msecTo(const QDateTime& fromdt,const QDateTime& todt){
              return 
              fromdt.time().mSecTo(todt.time())+(
              fromdt.date().daysTo(todt.date())*24*60*60*1000
              );
              }
              const QDateTime target(QDate(2017,2,15),QTime(10,30,0));
              QTimer::singleShot(msecTo(QDateTime::currentDateTime(),target),[]()->void{qDebug("2/15/2017 10:30:00 and all's well!");});
              
              A Offline
              A Offline
              ARASHz4
              wrote on last edited by
              #6

              @VRonin How about multi date & time? the count of date & time is dynamic
              so i don't know how many event user enter to my app
              Can i use only one QTimer? or i have to create a QTimer for each events ?

              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