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. Count 24houres with QDate

Count 24houres with QDate

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 681 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.
  • ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by ODБOï
    #1

    Hi,
    I want to restart my app every 24hs.
    startDate is QDate::currentDate when app starts.
    Do you think this works ?
    Please tell me how you would test this

    //this is called every 3 seconds in the app
            QDate dt = startDate;
            if(dt.addDays(1)<QDate::currentDate()){ 
                QTimer::singleShot(2000, this, [&](){
                    qApp->quit();
                    QProcess::startDetached(qApp->arguments()[0], qApp->arguments());    
                });
            }
    
    jsulmJ 1 Reply Last reply
    0
    • ODБOïO ODБOï

      Hi,
      I want to restart my app every 24hs.
      startDate is QDate::currentDate when app starts.
      Do you think this works ?
      Please tell me how you would test this

      //this is called every 3 seconds in the app
              QDate dt = startDate;
              if(dt.addDays(1)<QDate::currentDate()){ 
                  QTimer::singleShot(2000, this, [&](){
                      qApp->quit();
                      QProcess::startDetached(qApp->arguments()[0], qApp->arguments());    
                  });
              }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @LeLev said in Count 24houres with QDate:

      qApp->quit();
      QProcess::startDetached(qApp->arguments()[0], qApp->arguments());

      you should swap these two lines.

      "Please tell me how you would test this" - well, set the timeout to, for example 1min, and see whether it restarts or not.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      ODБOïO 1 Reply Last reply
      0
      • jsulmJ jsulm

        @LeLev said in Count 24houres with QDate:

        qApp->quit();
        QProcess::startDetached(qApp->arguments()[0], qApp->arguments());

        you should swap these two lines.

        "Please tell me how you would test this" - well, set the timeout to, for example 1min, and see whether it restarts or not.

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        hi @jsulm ,

        @jsulm said in Count 24houres with QDate:

        you should swap these two lines.

        it works like this also, but i will.

        @jsulm said in Count 24houres with QDate:

        set the timeout to, for example 1min

        Witch timeout ?

        jsulmJ 1 Reply Last reply
        0
        • ODБOïO ODБOï

          hi @jsulm ,

          @jsulm said in Count 24houres with QDate:

          you should swap these two lines.

          it works like this also, but i will.

          @jsulm said in Count 24houres with QDate:

          set the timeout to, for example 1min

          Witch timeout ?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @LeLev said in Count 24houres with QDate:

          Witch timeout ?

          The way you implement it currently can be simplified. Use a QTimer with a timeout of 24h, instead of executing the code above every 3sec.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          ODБOïO 1 Reply Last reply
          2
          • jsulmJ jsulm

            @LeLev said in Count 24houres with QDate:

            Witch timeout ?

            The way you implement it currently can be simplified. Use a QTimer with a timeout of 24h, instead of executing the code above every 3sec.

            ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by
            #5

            @jsulm said in Count 24houres with QDate:

            The way you implement it currently can be simplified. Use a QTimer with a timeout of 24h, instead of executing the code above every 3sec.

            That code needs to be executed anyway for something else thats why i wanted to do the test here.
            But Timer with 24h timeout is good also
            Thank you

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

              Hi,

              On what OS are you doing that ? Because from the looks of it, it would rather be a task for something like cron.

              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
              1

              • Login

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