Call function periodically (i.e. daily)
Solved
Mobile and Embedded
-
You can Use QTimer with a small Interval (1 minute, 1 hour) and when it expires you can check if you need to execute the function. (you can store the last execution time)
void MyClass::slotTimerExpired() { QDateTime nowUtc = QDateTime::currentDateTimeUtc(); if (m_lastExecutionTime.secsTo(nowUtc) >= 86400) // 1day = 86400 seconds { myfunction(); m_lastExecutionTime = nowUtc; } }
-
Hi,
Since you're running Linux, why not setup a cron job for that ?
-
@mcosta I agree, but depending on what that function should do, having a little helper program that can run without the need of the complete application might also be interesting. A cron job doesn't need to be built program, it can be written in e.g. python
-
Actually, the cron job would have been perfect for most of the periodic task, yes.
The periodic task is:- Download a file (SSL CA cert-bundle) from TFTP server (perfect for cron)
- Compare to current local copy (perfect for cron)
- If changed, replace local copy (perfect for cron)
- and then update QSsl with QSslSocket::addDefaultCaCertificates
Anyhow, I finished it in Qt and it works just perfect.
Thank you guys!..@SGaist : Grüess is Wallis us de Zentralschwiiz