QDateTime ts QDateTime currentDateTimeUtc QDateTime t1 ts addSecs -5 Q

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
QDateTime ts = QDateTime::currentDateTimeUtc();
QDateTime t1 = ts.addSecs(-5);
QDateTime t2 = ts.addSecs(5);
QVector<QDateTime> timeline;
int boo[] = {1,2,3,4,5,6};
foreach(int a, boo)
{
timeline.append(t1.addSecs(a));
}
bool found = false;
QDateTime prev = t1;
foreach(const QDateTime & curr, timeline)
{
qint64 dx = prev.msecsTo(ts);
qint64 dy = curr.msecsTo(ts);
if (dx < 0 && dy > 0)
{
yes = std::min(-dx, dy);
}
}