问题
The slot function QTimer::start have a interval of millisecond:
Starts or restarts the timer with a timeout interval of msec milliseconds.
But msec is a int
type and couldn't take a long interval. What is a alternative to QTimer
which could take a long interval ?
回答1:
In this case you can use something like an hourly timer connected to a function or lambda that checks the current timepoint against a target...
/*
* We want to trigger some event one year from now.
*/
auto endpoint = QDateTime::now().addYears(1);
QTimer hourly_timer;
QObject::connect(&hourly_timer, &QTimer::timeout,
[endpoint]()
{
if (QDateTime::now() >= endpoint) {
/*
* Target time reached. Do whatever...
*/
}
});
hourly_timer.start(3600 * 1000);
来源:https://stackoverflow.com/questions/62481663/what-is-the-alternative-to-qtimer