Solved Count 24houres with QDate
-
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()); }); }
-
@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.
-
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 ?
-
@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.
-
@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 -
Hi,
On what OS are you doing that ? Because from the looks of it, it would rather be a task for something like cron.