Example #1
0
void SignalMonitorTest::onTimeout()
{
    QTimer *tx = new QTimer(this);
    tx->setObjectName(nextTimerName());
    connect(tx, SIGNAL(timeout()), tx, SLOT(deleteLater()));
    tx->start(2500);
}
Example #2
0
void WeatherModel::replyFinished(QNetworkReply *reply)
{
    QByteArray data = reply->readAll();
    qDebug() << data;

    QJsonDocument doc = QJsonDocument::fromJson(data);

    QJsonObject query = doc.object().value("query").toObject();
    if (query.contains("results")) {
        QJsonObject res = query.value("results").toObject();
        QJsonObject cond = res.value("channel").toObject().value("item").toObject().value("condition").toObject();

        //m_results[reply->url()] = cond.value("text").toString();
        if (m_results.contains(reply->url())) {
            Report* r = m_results.value(reply->url());
            r->weather = cond.value("text").toString();
            r->lastSync = QDateTime::currentDateTime();
            emit dataChanged(createIndex(r->pos, 1),
                             createIndex(r->pos, 3));

            QTimer *t = new QTimer();
            t->setInterval(3000);
            t->setSingleShot(true);
            // Passing data in this way is simple, but not really pretty....
            t->setObjectName(reply->url().toString());
            connect(t, &QTimer::timeout,
                    this, &WeatherModel::updateData);
            t->start();
        }
    }
}
void SchedulerServiceThread::initTask(QString key){

    //Aktuelle Zeit
    uint time = QDateTime::currentDateTime().toTime_t();

    //Task holen
    SchedulerServiceThread::Task *task = this->_instructions->value(key);

    //Nur auf Event reagieren
    if(!task->event.isEmpty())
        return;

    //Einmalig aber noch nicht ausgeführt?
    if(task->once && !task->done){
        //Timer anlegen und starten
        QTimer *timer = new QTimer();
        timer->setInterval((task->seconds - time) * 1000);
        timer->setObjectName("singleTimer\n"+key);
        timer->start();

        //Timer registrieren
        this->_timers.insert(key,timer);

        //Command ausführen
        connect(timer,SIGNAL(timeout()),this,SLOT(executeCommand()));
        return;
    }

    if(!task->once){
        //Timer initialisieren
        QTimer *timer = new QTimer(0);
        timer->setInterval(task->seconds * 1000);
        timer->setObjectName("timer\n"+key);
        timer->start();

        //Timer registrieren
        this->_timers.insert(key,timer);

        //Command ausführen
        connect(timer,SIGNAL(timeout()),this,SLOT(executeCommand()));
        return;
    }
}
Example #4
0
void O2ReplyServer::onIncomingConnection() {
    qDebug() << "O2ReplyServer::onIncomingConnection: Receiving...";
    QTcpSocket *socket = nextPendingConnection();
    connect(socket, SIGNAL(readyRead()), this, SLOT(onBytesReady()), Qt::UniqueConnection);
    connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));

    // Wait for a bit *after* first response, then close server if no usable data has arrived
    // Helps with implicit flow, where a URL fragment may need processed by local user-agent and
    // sent as secondary query string callback, or additional requests make it through first,
    // like for favicons, etc., before such secondary callbacks are fired
    QTimer *timer = new QTimer(socket);
    timer->setObjectName("timeoutTimer");
    connect(timer, SIGNAL(timeout()), this, SLOT(closeServer()));
    timer->setSingleShot(true);
    timer->setInterval(timeout() * 1000);
    connect(socket, SIGNAL(readyRead()), timer, SLOT(start()));
}
Example #5
0
  void FileWatcher::monitorFileChanged_(const QString & name)
  {
    //static timer counter
    static int timer_id = 0;

    //cout << "File changed: " << String(name) << endl;
    //Look up if there is already a timer for this file
    QTimer * timer = 0;
    for (map<QString, QString>::const_iterator it = timers_.begin(); it != timers_.end(); ++it)
    {
      if (it->second == name)     //we found the timer name and id
      {
        //cout << " - Found timer name: " << String(it->second) << endl;
        //search for the timer instance with the corresponding Id
        timer = findChild<QTimer *>(it->first);
      }
    }

    //timer does not exist => create and start a new one
    if (!timer)
    {
      //cout << " - no timer found => creating a new one with name: ";
      timer = new QTimer(this);
      timer->setInterval((int)(1000.0 * delay_in_seconds_));
      timer->setSingleShot(true);
      timer->setObjectName(QString::number(++timer_id));
      connect(timer, SIGNAL(timeout()), this, SLOT(timerTriggered_()));
      timer->start();
      timers_[QString::number(timer_id)] = name;
      //cout << timer_id << endl;

    }
    //timer exists => restart it as the file changed another time
    else
    {
      //cout << " - timer found => resetting" << endl;
      timer->start();
    }
  }