Example #1
0
void Worker::timerEvent(QTimerEvent * ev)
{
    const int busyTime = 50; // [ms] - longest amount of time to stay busy
    const int testFactor = 128; // number of iterations between time tests
    const int maxCounter = 10000;
    if (ev->timerId() != m_timer.timerId()) return;

    QElapsedTimer t;
    t.start();
    while (1) {
        // do some "work"
        Helper::usleep(100);
        m_counter ++;
        // exit when the work is done
        if (m_counter > maxCounter) {
            emit progress(100);
            emit done();
            m_busy = false;
            break;
        }
        // exit when we're done with a timed "chunk" of work
        // Note: QElapsedTimer::elapsed() may be expensive, so we call it once every testFactor iterations
        if ((m_counter % testFactor) == 1 && t.elapsed() > busyTime) {
            emit progress(m_counter*100/maxCounter);
            break;
        }
    }
}
Example #2
0
 void timerEvent(QTimerEvent *ev) override {
    if (ev->timerId() == timer.timerId() && painter) {
       qreal const t = el.restart() / (qreal)10;
       for (auto &s : state)
          s.advance(t, dst.rect());
       update();
    }
 }
Example #3
0
void SharedTimerQt::timerEvent(QTimerEvent* ev)
{
    if (!m_timerFunction || ev->timerId() != m_timer.timerId())
        return;

    m_timer.stop();
    (m_timerFunction)();
}
Example #4
0
 void timerEvent(QTimerEvent * ev) override {
   if (ev->timerId() != m_timer.timerId()) return;
   int timeout = m_app->m_timeout;
   auto now = QDateTime::currentMSecsSinceEpoch();
   m_toEmit.clear();
   QMutexLocker lock(&m_app->m_mutex);
   for (auto it = m_app->m_threads.begin(); it != m_app->m_threads.end(); ++it) {
     if (it->ping == 0) continue;
     qint64 elapsed = now - it->ping;
     it->stuck = elapsed > timeout;
     m_toEmit.push_back({it.key(), it->stuck ? elapsed : 0});
   }
   lock.unlock();
   for (auto &sig : qAsConst(m_toEmit)) emit m_app->loopStateChanged(sig.thread, sig.elapsed);
 }
Example #5
0
 void timerEvent(QTimerEvent *ev) override {
    if (ev->timerId() == m_timer.timerId())
       refreshImage();
 }
Example #6
0
 void timerEvent(QTimerEvent * ev) {
    if (ev->timerId() != m_queryTimer.timerId()) return;
    m_queryTimer.stop();
    emit queryRequest();
 }